Execution priority

  • Thread starter Thread starter Harry J. Smith
  • Start date Start date
H

Harry J. Smith

How can a program change its execution priority in the operating system while it is running?

-Harry
 
Hi Harry,

Harry J. Smith said:
How can a program change its execution priority in the operating system
while it is running?

-Harry

Try tweaking:

System.Threading.Thread.CurrentThread.Priority

and

System.Diagnostics.Process.GetCurrentProcess().PriorityClass.
 
using System.Threading;
....
Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
....

--Richard
 
Thanks!

The following code works and does what I was looking for, but in Windows XP pro that I am using the Windows Task Manager still shows
the Base Priority as Normal. I can tell by looking at CPU percent of utilization that the code is working.

using System.Threading; // for Thread

public static void GetPriority() // display priority status
{
string st = Thread.CurrentThread.Priority.ToString();
Console.WriteLine("Priority is " + st);
}

public static void SetPriority(int p) // change priority to p
{
if (p == 2)
Thread.CurrentThread.Priority = ThreadPriority.Highest;
else if (p == 1)
Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
else if (p == -1)
Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
else if (p == -2)
Thread.CurrentThread.Priority = ThreadPriority.Lowest;
else
Thread.CurrentThread.Priority = ThreadPriority.Normal;
GetPriority();
}

-Harry
 
Back
Top