Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. public object getCPUCounter()
  2.     {
  3.  
  4.         PerformanceCounter cpuCounter = new PerformanceCounter();
  5.         cpuCounter.CategoryName = "Processor";
  6.         cpuCounter.CounterName = "% Processor Time";
  7.         cpuCounter.InstanceName = "_Total";
  8.  
  9.         // will always start at 0
  10.         dynamic firstValue = cpuCounter.NextValue();
  11.         System.Threading.Thread.Sleep(1000);
  12.         // now matches task manager reading
  13.         dynamic secondValue = cpuCounter.NextValue();
  14.  
  15.         return secondValue;
  16.  
  17.     }
  18. // make button in the design and put this code
  19.     protected void Button3_Click(object sender, EventArgs e)
  20.     {
  21.    
  22.     var cpuPercent = getCPUCounter();
  23.         PerformanceCounter theMemCounter =
  24.    new PerformanceCounter("Memory", "Available MBytes");
  25.     var mem = theMemCounter.NextValue();
  26.         Response.Write("the cpu value  "+ cpuPercent  +"  % " +  "    the memory value    " + mem );
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement