Re: Performance counter throws error
- From: Pavel Minaev <int19h@xxxxxxxxx>
- Date: Tue, 15 Jul 2008 05:14:26 -0700 (PDT)
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.
.
- Follow-Ups:
- Re: Performance counter throws error
- From: sony . m . 2007
- Re: Performance counter throws error
- References:
- Performance counter throws error
- From: sony . m . 2007
- Performance counter throws error
- Prev by Date: Help! StarSP200 printing component
- Next by Date: Learning C# - Looking for a good, free IDE
- Previous by thread: Performance counter throws error
- Next by thread: Re: Performance counter throws error
- Index(es):
Relevant Pages
|