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