C# program to set the priorities to the threads
Program.cs
Explanation:
In this program, we have created one class named PriorityThread, and in the main method, we have created the objects of PriorityThread and Thread class, and passed those objects as an argument in ThreadStart delegate. With the help of Priority property and ThreadPriority Enum, we set the priority of threads. There are five fields available to set the thread priorities: AboveNormal 3, BelowNormal 1, Highest 4, Lowest 0, and Normal 2.
The high priority thread can be executed first. But it is uncertain that the high priority thread gets executed first as the threads are highly system dependent. Lastly, we have used the Start() method of Thread class to begin the execution. Technically, the thread will move from ready-to-run state to runnable state.
The high priority thread can be executed first. But it is uncertain that the high priority thread gets executed first as the threads are highly system dependent. Lastly, we have used the Start() method of Thread class to begin the execution. Technically, the thread will move from ready-to-run state to runnable state.
Output
kodingwindow@kw:~/csharp$ dotnet run MongoDB Server Is Running Cassendra Server Is Running MySQL Server Is Running kodingwindow@kw:~/csharp$
What Next?
C# program for sleep(), abort() and join() methods
C# program to achieve thread synchronization using the lock keyword
C# Reflection
Advertisement