none
PerformanceCounter error RRS feed

  • 问题

  • Unhandled Exception: System.InvalidOperationException: Could not locate Performance Counter with specified category name 'Process', counter name 'Working Set -Private'.
       at System.Diagnostics.PerformanceCounter.InitializeImpl()
       at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly)
       at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName)
       at CSharpPerformance.ProcessPerformanceInfo.netRefershInfo() in D:\科研-论文\毕设\参考程序\CSharpPerformance\CSharpPerformance\ProcessPerformanceInfo .cs:line 226
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

    我在程序中是这样使用PerformanceCounter的,代码如下:

    //获取当前进程对象

                Process cur = process;
                PerformanceCounter curpcp = new PerformanceCounter("Process", "Working Set - Private", cur.ProcessName);
                PerformanceCounter curpc = new PerformanceCounter("Process", "Working Set", cur.ProcessName);
                PerformanceCounter curtime = new PerformanceCounter("Process", "% Processor Time", cur.ProcessName);

    //得到process的代码

            public  ProcessPerformanceInfo(int id,string path)
            {
                foreach(Process ps in Process.GetProcesses())
                {
                    if( ps.Id==id)
                    {
                        //获取当前进程对象
                        this.ProcessID=id;
                        this.process=ps;

                        break;
                    }
                }

            }

    这个程序在我的win7-x64下测试成功,但是在server2003-x64下测试不成功,使用的是.net4.

    2014年11月9日 14:48

全部回复