For some reason, my performance counter doesn't work. I saw this performance counter working on other people's laptop & desktop, but not mine. It doesn't have a list to let me choose, and other people do not have this problem at all. Even though I catch it from server manager I guess, and put it on to the form, it is still showing "System.Diagnostic.PerformanceCounter" Which is very annoying at all.
using System;
using System.Diagnostics;
using Microsoft.WindowsAzure.Diagnostics;
namespace MonitorC
{
public partial class Form1 : MetroFramework.Forms.MetroForm
{
//PerformanceCounter perfCPUCounter = new PerformanceCounter("Processor Information", "% Processor Time", "_Total");
//PerformanceCounter perfRAMCounter = new PerformanceCounter("Memory", "Available MBytes");
//PerformanceCounter perfSysCounter = new PerformanceCounter("System", "System Up Time");
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
CPUusage.Text = performanceCounter1.ToString();
RAMusage.Text = performanceCounter2.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
}
}
}
1st image:
2nd image:
3rd image:
Code I have:
You just need to add call to NextSample
to get raw value or NextValue
to get calculated value. Like this:
performaceCounter1.NextValue().ToString();