C # program, how to effectively reduce CPU usage,

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.