如何在C#中获取当前线程的状态?
要获取当前线程的状态,请使用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
热门推荐
10 小侄过生日祝福语简短
11 小店营业的祝福语简短
12 担任老师的祝福语简短
13 饮料吧台祝福语简短大气
14 公司新春搞笑祝福语简短
15 高情商敬酒祝福语简短
16 婚礼祝福语新郎妹妹简短
17 教师答辩通过祝福语简短
18 生女孩红包简短祝福语