I have a program written in C#, I am using VSTS 2008 + .Net 3.5 + Windows Vista Enterprise x86 to develop a Windows Forms application.
My current computer is dual-core CPU, I want to set CPU affinity of my program to run on a specific CPU and free another CPU to do some other job. Any ideas how to do this? Either through coding or configuration is ok.
A little more background is, my program is CPU intensive, so I do not want to let it occupy all two CPU resources on my computer and I want to free one CPU so that I can browse network at the same time quickly. :-)
thanks in advance, George
This should free up one processor for you.
For doing it from the code you can add this statement:
System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr) 1;
Cheers!
The Windows API functions to do this are SetProcessAffinityMask() and SetThreadAffinityMask(). I don't know .NET so I can't say whether there are wrappers around those functions, but this seems to suggest otherwise.
BTW: I agree that these are necessary only in very specific circumstances, it's normally best to let the OS scheduler deal with it. It's one of those questions where you probably shouldn't do it if you have to ask how.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With