I would like to write a .NET application that runs in the background (stays down in the taskbar) and does a long operation like copying folders of files from one location to another. I want to write it in such a way that other applications that are running don't slow down much. I don't care how long the background app takes. Is there a way that I can limit the processing/memory resources for the application. I know when you create threads you can set their priorities to different levels. Would setting a thread priority to low have this effect or would it only have less priority than any other threads that are part of the same application?
views:
47answers:
2
+3
A:
Yes, you can create a new Thread
and set the Priority
property before starting it:
Thread thread = new Thread(MethodToRun);
thread.Priority = ThreadPriority.Lowest;
thread.Start();
Steven
2010-02-24 15:51:57
+1
A:
If you're looking for something with the precision of NICE in unix, I'm not sure of any exists. But you can set the priority of the process which may help.
System.Diagnostics.Process.GetCurrentProcess().PriorityClass =System.Diagnostics.ProcessPriorityClass.Low;
Hope that helps.
Jeremy Morgan
2010-02-24 15:52:27
What will this do differently than Stevens suggestion?
Jordan S
2010-02-24 16:36:09
Steven's solution works per thread, my post was per process. If I understand it correctly, by setting the priority class all threads in your process will be prioritized relative to the process itself. By setting the process priority you're capping every thread to that priority. However Steven's solution may be better, because you may want that kind of finite control, rather than dropping the priority of everything. I have +1 his solution as well.
Jeremy Morgan
2010-02-24 20:25:46
"Steven's solution may be better". You read that Jordan? Mark me as answer :-P
Steven
2010-02-26 15:38:54