C# program to implement Thread class and its properties
Program.cs
Explanation:
In the above program, we have created a reference variable of Thread class and stored the CurrentThread in it, and with the help of the reference variable, we have printed the various properties of a thread on the Console. The explanation for each property is given below:
1. The Name property used to set and get the name of current thread (by default value of the Name property is null)
2. The Priority property used to set or get the priority of thread
3. The IsAlive property used to check whether the thread is alive or dead
4. The IsThreadPoolThread property used to check whether a thread belongs to managed thread pool
5. The ManagedThreadId property used to get a unique identifier for the currently managed thread
6. The ThreadState property used to get and set the state of thread
1. The Name property used to set and get the name of current thread (by default value of the Name property is null)
2. The Priority property used to set or get the priority of thread
3. The IsAlive property used to check whether the thread is alive or dead
4. The IsThreadPoolThread property used to check whether a thread belongs to managed thread pool
5. The ManagedThreadId property used to get a unique identifier for the currently managed thread
6. The ThreadState property used to get and set the state of thread
Output
kodingwindow@kw:~/csharp$ dotnet run Main Thread Normal True en-US False 1 Running kodingwindow@kw:~/csharp$
What Next?
C# implementation of Multithreading
C# program to demonstrate two threads working concurrently
C# program to set the priorities to the threads
Advertisement