Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public object getCPUCounter()
- {
- PerformanceCounter cpuCounter = new PerformanceCounter();
- cpuCounter.CategoryName = "Processor";
- cpuCounter.CounterName = "% Processor Time";
- cpuCounter.InstanceName = "_Total";
- // will always start at 0
- dynamic firstValue = cpuCounter.NextValue();
- System.Threading.Thread.Sleep(1000);
- // now matches task manager reading
- dynamic secondValue = cpuCounter.NextValue();
- return secondValue;
- }
- // make button in the design and put this code
- protected void Button3_Click(object sender, EventArgs e)
- {
- var cpuPercent = getCPUCounter();
- PerformanceCounter theMemCounter =
- new PerformanceCounter("Memory", "Available MBytes");
- var mem = theMemCounter.NextValue();
- Response.Write("the cpu value "+ cpuPercent +" % " + " the memory value " + mem );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement