Re: Performance counter throws error

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Jul 15, 3:32 pm, sony.m.2...@xxxxxxxxxxxxxx wrote:
Hi,
I'm using VSTS2008.
I tried to create a performance counter as below.

A simple example of monitoring processor usage (similar to what's seen
in task manager):

Code Snippet

using System;

using System.Diagnostics;

using System.Threading;

namespace PerfmonExample

{

   class Program

   {

      static void Main(string[] args)

      {

         PerformanceCounter processorUsage = new
PerformanceCounter("Processor", "% Processor Time", "_Total",false);

         while (true)

         {

            Console.WriteLine(processorUsage.NextValue());

            Thread.Sleep(2000);

         }

      }

   }

}

When i run the above code, it throws  error  as "The requested
Performance Counter is not a custom counter, it has to be initialized
as ReadOnly."
What could be the problem for this error?

It is precisely what it says: when you called the constructor of
PerformanceCounter, you've passed "false" as the last argument, which
is named "readOnly". Try "true" instead.
.



Relevant Pages

  • Re: Alerts not working
    ... requested Performance Counter is not a custom counter, ... counterName, String instanceName, Boolean readOnly) at ...
    (microsoft.public.sharepoint.portalserver)
  • Re: Performance counter throws error
    ... Performance Counter is not a custom counter, ... False means  to access a counter in read/write mode. ... Time" system counter? ...
    (microsoft.public.dotnet.languages.csharp)
  • Performance counter throws error
    ... I tried to create a performance counter as below. ... A simple example of monitoring processor usage (similar to what's seen ... in task manager): ... static void Main(stringargs) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Performance counter throws error
    ... Performance Counter is not a custom counter, ... False means  to access a counter in read/write mode. ... Time" system counter? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Performance counter throws error
    ... I tried to create a performance counter as below. ... in task manager): ... Performance Counter is not a custom counter, ... The same code working fin in VS2005. ...
    (microsoft.public.dotnet.languages.csharp)