In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what is the priority of C # threads". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the priority of C # threads?"
Necessity of C # thread priority: what to do if there are multiple threads running in the application, but some threads are more important than others? in this case, different threads can be assigned different priorities in one process. In general, if there is a higher priority thread working, no time slice will be assigned to the lower priority thread, which has the advantage of assigning a higher priority to the thread receiving user input. Most of the time, this thread does nothing, while other threads perform their tasks. However, if the user enters information, the thread immediately gets a higher priority than other threads in the application and processes user input events in a short period of time.
The rule of C # thread priority: high-priority threads can completely block the execution of low-priority threads, so be especially careful when changing the priority of threads. The priority of a thread can be defined as the values of the ThreadPriority enumeration, namely Highest, AboveNormal, Normal, BelowNormal, and Lowest.
Note that each process has a basic priority, and these values are related to the priority of the process. Assigning a thread a higher priority ensures that it takes precedence over other threads in that process, but there may be other processes running on the system whose threads have a higher priority. So Windows assigns high priority to its own operating system threads.
In the ThreadPlayaround example, you can see the effect of changing the priority of the thread by making the following changes to the Main () method:
ThreadStart workerStart = new ThreadStart (StartMethod); Thread workerThread = new Thread (workerStart); workerThread.Name = "Worker"; workerThread.Priority = ThreadPriority.AboveNormal; workerThread.Start ()
The priority of the worker thread is higher than that of the main thread, and the running result is as follows:
ThreadPlayaroundWithPriorities Interval to display results at > 1000000 Starting thread: Main Thread Main Thread: Current Culture = en-US Starting thread: Worker Worker: Current Culture = en-US Main Thread: count has reached 1000000 Worker: count has reached 1000000 Worker: count has reached 2000000 Worker: count has reached 3000000 Worker: count has reached 4000000 Worker: count has reached 5000000 Worker: count has reached 6000000 Worker: count has reached 7000000 Worker: count has reached 8000000 Worker Thread Finished Main Thread: count has reached 2000000 Main Thread: count has Reached 3000000 Main Thread: count has reached 4000000 Main Thread: count has reached 5000000 Main Thread: count has reached 6000000 Main Thread: count has reached 7000000 Main Thread: count has reached 8000000 Main Thread Finished
This means that when the priority of the worker thread is AboveNormal, once the worker thread is started, the main thread is no longer running.
At this point, I believe you have a deeper understanding of "what is the priority of C # threads". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.