Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么性能计数器根本不工作_C#_Winforms_Visual Studio 2017_Performancecounter - Fatal编程技术网

C# 为什么性能计数器根本不工作

C# 为什么性能计数器根本不工作,c#,winforms,visual-studio-2017,performancecounter,C#,Winforms,Visual Studio 2017,Performancecounter,由于某种原因,我的性能计数器不工作。我看到这个性能计数器在其他人的笔记本电脑和台式机上工作,但不是我的。 它没有让我选择的列表,其他人根本没有这个问题。即使我从服务器管理器中捕捉到它,并将它放到表单中,它仍然显示“System.Diagnostic.PerformanceCounter”,这一点都很烦人 using System; using System.Diagnostics; using Microsoft.WindowsAzure.Diagnostics; namespace Moni

由于某种原因,我的性能计数器不工作。我看到这个性能计数器在其他人的笔记本电脑和台式机上工作,但不是我的。 它没有让我选择的列表,其他人根本没有这个问题。即使我从服务器管理器中捕捉到它,并将它放到表单中,它仍然显示“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();

请复制粘贴您的代码在这里,因为它是没有用的,我们如果他们是imagesOk我做了,如果你需要整个sln,我可以给它。