Thematic Priorities

How big is the difference between ThreadPriority.Lowest and ThreadPriority.BelowNormal .

How to find out which one to choose? I have computations with processor intensive computation, and I don't want them to affect the rest of the application.

Update

The task starts from System.Threading.Timer . Do I have a reset thread priority before the callback method returns, or will .Net handle this?

+4
source share
5 answers
The answers of Darin and Matt are completely correct and probably complete. I just add extra words here: p

The basic idea is that priorities really make sense in relation to each other. The work of lower priorities (effectively) will not be achieved until there is more work at the higher priorities that need to be performed. This is why it is so dangerous to raise the priority of processes / threads too high - you could effectively block the rest of the system.

Also note that the priority of your thread affects the rest of the system, not the rest of your application. But also note that the OS itself freely adjusts the relative priorities of the threads on the fly (therefore, I continue to use the word effectively).

+3
source

Be careful when setting the priority of a stream.

As long as you don’t want the process to affect the rest of the application’s response, decreasing the priority of the thread, this may mean that the thread takes a lot longer. This may have a seemingly more serious impact on the application, as the user is obviously waiting for it to complete.

You should check the effect of changing priority on different machines with different loads. Setting the priority to the lowest will have a significant impact on thread execution time.

You can also consider using an option (which may be hidden to some extent), allowing the user to control the priority of the stream (or at least choose between two or three average values.

+1
source

Have you looked? MSDN Thread Priority

Threads are scheduled for execution based on their priority. The scheduling algorithm used to determine the execution order of threads depends on each operating system. The operating system can also dynamically adjust the priority of the stream, as the focus of the user interface moves between the foreground and background.

Specific for your question:

The lowest thread can be scheduled after threads with any other priority.

BelowNormal Thread can be scheduled after threads with normal priority and before those with the lowest priority.

0
source

The documentation looks pretty clear. Use Lowest if you want threads to be scheduled after threads with any other priority. Use BelowNormal if you want threads to be scheduled after threads with Normal priority and before those with Lowest priority.

0
source

Which choice to choose depends on your situation, but I consider it this way:

If the process is completely background and not too critical, Lowest.

If the process should happen, but the time is not critical, below Normal.

If the process is just as important as everyone else, Normal.

I try not to use higher ones, my programs are not so important :)

As for the difference, it depends on the code run and what the OS decides to do with the priorities, it does not need to listen to the one you installed.

0
source

Source: https://habr.com/ru/post/1344903/


All Articles