fguihen Posted April 19, 2005 Posted April 19, 2005 you know where in task manager you can set the priority of a thread, so it gets max cpu time, well is there any way to do that in c# code to make my app top priority?? Quote
HJB417 Posted April 19, 2005 Posted April 19, 2005 There are several ways to approach it. Here's an example of 2 ways. 1 uses the process name to set the thread priority of all of the threads in all of the processes with the matching name. 2 uses the process id to set the thread priority of all of the threads found in a specific process id. static void SetPriority(string processName, System.Threading.ThreadPriority priority) { if(processName == null) throw new ArgumentNullException("processName"); System.Diagnostics.Process[] proccesses = System.Diagnostics.Process.GetProcessesByName(processName); foreach(System.Diagnostics.Process process in proccesses) foreach(System.Threading.Thread thread in process.Threads) thread.Priority = priority; } static void SetPriority(int processId, System.Threading.ThreadPriority priority) { System.Diagnostics.Process process = System.Diagnostics.Process.GetProcessById(processId); foreach(System.Threading.Thread thread in process.Threads) thread.Priority = priority; } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.