Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use ThreadPriority to set thread priority in C #

Shulou Source: shulou.com Published: 2022-05-31 20:47:21 09月22日 Update

Most people do not understand the knowledge points of this article "how to use ThreadPriority to set thread priority", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "how to use ThreadPriority to set thread priority in C#".

I. brief introduction

If you have multiple threads running in your application, but some threads are more important than others, you can assign different priorities to different threads in a process. The priority of a thread can be set through the Priority property of the Thread class, which is a ThreadPriorty type enumeration that enumerates five priorities: AboveNormal, BelowNormal, Highest, Lowest, and Normal. The common language runtime is of type Normal by default.

Code class Program {static void Main (string [] args) {Thread threadA = new Thread (ThreadMethod); / / must be a method with no return value threadA.Name = "A"; Thread threadB = new Thread (ThreadMethod); threadB.Name = "B"; threadA.Priority = ThreadPriority.Highest; threadB.Priority = ThreadPriority.BelowNormal ThreadB.Start (); threadA.Start (); Thread.CurrentThread.Name = "C"; / / default is Normal ThreadMethod (new object ()); Console.ReadKey ();} public static void ThreadMethod (object parameter) {for (int I = 1; I)

Tags: Thread priority content time run caching different code multiple attributes meaning article more knowledge article result assignment lowest highest important Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology macOS OPPO Reno Shulou Tech Info