Causes CPU usage increasing

Problems caused by the project found that:

  Combined with other friends opinion, my idea is to optimize:

    1, whether a memory leak investigation

        After repeated query code, we found no memory leaks (can own Baidu search for the cause of memory leaks C #). Is there a memory leak can be analyzed through the Task Manager, open the Task Manager - Performance - open Resource Monitor, then you can check the CPU, memory, disk, network and other information

    2, the investigation is not closed if there is a thread

        Thread cause is not closed, then open up the thread after I remember when not in use

        thread.DisableComObjectEagerCleanup();
                      thread.Abort();

            3, may be used in addition to those in the control program of CPU, thereby avoiding unnecessary opening CPU consumption. Specific implementation code to find the degree of your mother.

      Reference: Process to control the main thread

      

 1 public static void SetProcess()
 2         {
 3             Process p = new Process();
 4             p.StartInfo.FileName = System.IO.Directory.GetCurrentDirectory() + "\\Test.exe";
 5             p.StartInfo.RedirectStandardError = true;
 6             p.StartInfo.RedirectStandardOutput = true;
 7             p.StartInfo.UseShellExecute = false;
 8             p.StartInfo.CreateNoWindow = true;
 9             p.Start ();
 10  
. 11              // Set the number of CPU use, used here CPU0 and the CPU 1 
12 is              p.ProcessorAffinity = (IntPtr) ( 0x0001 | 0x0002 );
 13 is              p.Close ();
 14              p.Dispose ();
 15          }
View Code

    4, CPU utilization is too high, the thread can be added to reduce the time interval molecules, such as your thread running speed every 10 seconds and 10 milliseconds each effect is completely different to the (according to the configuration of the computer different effects not the same), or directly while (true); l CPU usage to detect more directly seen.

To be perfect!

      

Guess you like

Origin www.cnblogs.com/LiuL123-321/p/12133345.html