开发者

Can you limit the processing resources that an application can use in .NET

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 开发者_JAVA百科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?


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();


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜