如何在 C# 中获取当前线程的状态?
csharpprogrammingserver side programming更新于 2025/5/25 3:52:17
要获取当前线程的状态,请使用 IsAlive() 方法 −
首先,创建一个新线程 −
Thread t = Thread.CurrentThread; t.Name = "Our Thread";
现在,获取当前线程的状态 −
t.IsAlive
以下是完整代码 −
示例
using System;
using System.Threading;
namespace Demo {
class MyClass {
static void Main(string[] args) {
Thread t = Thread.CurrentThread;
t.Name = "Our Thread";
Console.WriteLine("Status = {0}", t.IsAlive);
Console.ReadKey();
}
}
}
输出
Status = True

