Thread Priority

14 08 2011

A thread’s Priority property determines how much execution time it gets relative to other active threads in the operating system. The options are:

enum ThreadPriority { Lowest, BelowNormal, Normal, AboveNormal, Highest }

This becomes relevant only when multiple threads are simultaneously active. Raising a thread’s priority can lead to problems such as resource starvation for other threads. A thread’s priority is throttled by the application’s process priority. To perform real-time work, you must also elevate the process priority using the Process class in System.Diagnostics:

using (Process p = Process.GetCurrentProcess()) 
    p.PriorityClass = ProcessPriorityClass.High;

The top ProcessPriorityClass is Realtime. Setting a process priority to Realtime instructs the OS that you’re process should never yield CPU time to another. If your program enters an accidental infinite loop, you can find that the power button is your only option! For this reason, High is usually the best choice for real-time applications.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: