Force C # application for using a single core on a PC with a multi-core processor

Hi guys, this question may seem strange, but I use the Haptek People Putty player for my C # application, and I saw people say on the forums that it does not work well with a multi-core processor. My application works well on my Core 2 Duo laptop, but it crashes a lot when I try to run it on the Quad Core desktop. I thought about it for myself, and in this case I would have to get my application to work on one core. Is this possible in C #? Thanks!

+7
c # core
source share
3 answers

If the Process proc variable contains the required process ( Process.GetCurrentProcess() for the current process, get it from GetProcesses() or GetProcessesByName() , etc. for another process. Then:

 foreach(ProcessThread pt in proc.Threads) { pt.IdealProcessor = 0; pt.ProcessorAffinity = (IntPtr)1; } 

IdealProcessor is the null identifier of a single core. ProcessorAffinity is a bitmask, therefore 1 allows zero zero, 2 allows one core, 3 allows zero and one kernels, 4 allows two kernels, etc.

I would check this out completely . The odds are very strong that it will actually hurt your performance, reducing the ability to use different cores, which is usually an advantage.

+3
source share

If the application is single-threaded, it will not use multiple cores. However, it is possible that the nucleus may strike a stream around the nuclei. I doubt this is causing your performance problems.

If you want to bind a thread to one core (not sure if this can be guaranteed), you can check the System.Diagnostics.ProcessThread.ProcessorAffinity property, although I never used it myself.

+2
source share
  • Impossible to IN C #. Well, I do not know. You need interop, it works with that.

  • Do you use multiple threads? If not - hmm - sorry - not much you can do. Standard user interface applications do not use multiple cores anyway.

In principle, applications that do not use Threads (work items use threads) are essentially single-core.

+1
source share

All Articles