为什么性能计数器根本不工作
Why is performance Counter Not Working At all
出于某种原因,我的性能计数器不起作用。我看到这个性能计数器在其他人的笔记本电脑和台式机上工作,但不是我的。
它没有列表让我选择,其他人根本没有这个问题。尽管我猜是从服务器管理器那里捕获的,并将其添加到表单中,但它仍然显示 "System.Diagnostic.PerformanceCounter" 这非常烦人。
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();
}
}
}
第一张图片:
第二张图:
第三张图片:
我有代码:
您只需添加对 NextSample
的调用以获取原始值或添加对 NextValue
的调用以获取计算值。像这样:
performaceCounter1.NextValue().ToString();
出于某种原因,我的性能计数器不起作用。我看到这个性能计数器在其他人的笔记本电脑和台式机上工作,但不是我的。 它没有列表让我选择,其他人根本没有这个问题。尽管我猜是从服务器管理器那里捕获的,并将其添加到表单中,但它仍然显示 "System.Diagnostic.PerformanceCounter" 这非常烦人。
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();
}
}
}
第一张图片:
第二张图:
第三张图片:
我有代码:
您只需添加对 NextSample
的调用以获取原始值或添加对 NextValue
的调用以获取计算值。像这样:
performaceCounter1.NextValue().ToString();