C# program to check current thread status

王林
Release: 2023-09-13 10:41:02
forward
1224 people have browsed it

检查当前线程状态的 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;
Copy after login

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

thread.IsAlive
Copy after login

Example

Let us see the complete code to check the status of current thread in C#.

Live Demo

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();
      }
   }
}
Copy after login

输出

Thread Status = True
Copy after login

The above is the detailed content of C# program to check current thread status. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!