Tuesday, November 6, 2012

Check CPU uses for critical situation by C# Step By Step

There may occur many problem in your computer,your computer CPU uses may increases and It harm your computer process,so you need to check all the time your CPU uses if it goes above 90% and you should notified.
This simple demo project will help you to check the uses of CPU.

Here is the step by step procedure to get the CPU uses by C# windows form application.

Step 1 :

Take a project New Project,C# windows form application.

Step 2:

Get a Timer from toolbar.

then a label.




Step 3 :


Code the timer.tick like as follow




static PerformanceCounter puUsage = new PerformanceCounter("Processor Information", "% Processor Time", "_Total");
       



 private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = cpuUsage.NextValue() + " %";
            int use= Int32.Parse(cpuUsage.NextValue().ToString());

            if ( use>= 20)
                hit++;
            else
                hit=0;
            if (hit == 60)
            {
                label3.Text = "Warning Cpu is hitttttt";
            }
           // Thread.Sleep(1000);
         //   label1.Text = cpuUsage.NextValue() + " %";
            
        }


or you can download demo project from the below link.






No comments:

Post a Comment