C# 程序,检查当前线程状态
若要检查 C# 中当前线程的状态,请使用 IsAlive 属性。
首先,使用 currentThread 属性显示线程信息 -
Thread thread = Thread.CurrentThread;
现在使用 thread.IsAlive 属性检查线程的状态 -
thread.IsAlive
示例
让我们看看完成的代码,以便在 C# 中检查当前线程的状态。
using System;
using System.Threading;
namespace Demo {
class MyClass {
static void Main(string[] args) {
Thread thread = Thread.CurrentThread;
thread.Name = "My New Thread";
Console.WriteLine("Thread Status = {0}", thread.IsAlive);
Console.ReadKey();
}
}
}输出
Thread Status = True
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP