如何在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 教师闺蜜祝福语简短