如何在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 宝宝生病简短祝福语大全