下面的代码文身么不行呢?CategoryName、CounterName、InstanceName三个参数是系统指定好的变量名吧?请指教。CategoryName="Process";
CounterName="CounterName";
PerformanceCounter  pc=  new  PerformanceCounter(CategoryName,CounterName,true);

解决方案 »

  1.   

    CounterName="CounterName";
    你定义了这个计数器吗?
    还有CategoryName="Process"的话需要指定个InstanceName(你想知道信息所属线程的名字)吧?MSDN的简单例子
    PerformanceCounter PC=new PerformanceCounter();
    PC.CategoryName="Process";
    PC.CounterName="Private Bytes";
    PC.InstanceName="Explorer";
    MessageBox.Show(PC.NextValue().ToString());
      

  2.   

    加上定义计数器,完整的代码应该怎么写?我就是想统计目前服务器的CPU的占用率,不是统计某一个线程的。谢谢指教!我刚用C#,以前都是C++,现在发现C#在2003平台很好用啊。
      

  3.   

    MSDN中:
    说明如何使用性能计数器监视系统性能ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cssample/html/vcsamperfmonsamplecsharp.htm