检查当前线程状态的 C# 程序

王林
王林 转载
2023-09-13 10:41:02 804浏览

检查当前线程状态的 C# 程序

To check the status of the current thread in C#, use the IsAlive property.

Firstly, use the currentThread property to display information about a thread −

Thread thread = Thread.CurrentThread;

Now use the thread.IsAlive property to check the status of the thread −

thread.IsAlive

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

以上就是检查当前线程状态的 C# 程序的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除