Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how i can Adjustment priority threads and BackGrounWorkers with "Thread.Priority" ?
Posted

If you need to set a thread's priority, you should use the Thread object instead of BackgroundWorker.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Feb-11 0:22am    
You should have also warned against modification of priority -- I provided explanation, please see my answer.
--SA
Normally, you never need to modify priorities.
There may be no harm (unless you make priority two high blocking important thread, even of the OS), but usually no use.

All attempts I ever so was due to misconception. People devised wrong design first, faced with problems. To solve these problem they attempted to modify priority and got some improvements. In fact, the improvements were illusory: they only changes their race conditions.

Read on race condition, it may help a lot: http://en.wikipedia.org/wiki/Race_condition[^]. Years ago I used to read about same thing in much more definitive terminology: "Incorrect dependency on the order of execution". Does this term provide a hint for you?

—SA
 
Share this answer
 
v2
Comments
JF2015 4-Feb-11 0:28am    
Good advice that is very important to know. 5+
Sergey Alexandrovich Kryukov 4-Feb-11 0:36am    
Thanks a lot. Couple of type fixed. Last clause is about a "hint".
--SA
In your DoWork() you could try
C#
Thread.CurrentThread.Priority = ThreadPriority.Lowest; // or .Highest or whatever
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Feb-11 0:22am    
You should have also warned against modification of priority -- I provided explanation, please see my answer.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900