C # program, how to effectively reduce CPU usage,
Recently developed projects use a third-party program ffmpeg that consumes CPU resources to process videos. So I found out how to solve this problem on the Internet.
Therefore, we can draw a conclusion that to reduce the CPU usage, you can reduce the number of CPUs used. In the Window system, open an exe program and the system will use all the CPUs by default for processing.
Is it possible to reduce the CPU usage by reducing the CPU usage? The answer is yes.
Reference code: Use calc as an example.
Process p = new Process (); p. startInfo. fileName = @ "c: \ windows \ system32 \ calc.exe"; p. startInfo. redirectStandardOutput = true; p. startInfo. redirectStandardError = true; // redirect p. startInfo. useShellExecute = false; p. startInfo. createNoWindow = true; // No window p. start (); // set the number of CPUs used. CPU0 and CPU1 p are used here. processorAffinity = (IntPtr) (0x0001 | 0x0002); p. close (); p. dispose ();
The number of CPU after modification is reduced, and the CPU usage will be greatly reduced during use.
There are still many ways to reduce CPU usage. I heard that there are hardware acceleration and so on, but these functions have not been used yet.