PerformanceCounterCategory woes

  • Thread starter Dmitriy Lapshin [C# / .NET MVP]
  • Start date
D

Dmitriy Lapshin [C# / .NET MVP]

Hello all,

This is a long post but I'd better provide all the details from the outset
to prevent cluttering the NGs with clarifications. I also apologize for
cross-posting, I am just not sure what area the root of the problem belongs
to.

So, I am currently trying to resolve a very puzzling problem with the
PerformanceCounterCategory class. Suppose we have the following code
snippet:

<codeSnippet>
bool ok = true;

if (!PerformanceCounterCategory.Exists("My category"))
{
ok = false;
}

if (ok && !PerformanceCounterCategory.CounterExists(
"Counter Name 1",
"My category"))
{
ok = false;
}

if (ok && !PerformanceCounterCategory.CounterExists(
"Counter Name 2",
"My category"))
{
ok = false;
}
</codeSnippet>

Most of the time, the code above works OK. Sometimes, however, it chokes on
the CounterExists method call - an InvalidOperationException is thrown with
Message saying "Category does not exist". The stack trace points to a
PerformanceCounterLib class which seems to be not documented.

It's strange, isn't it - the Exists method has just reported the category
*does* exist. Well, now the symptoms:

a) It is an ASP .NET application
b) The ASPNET user has been granted permissions to the appropriate registry
keys (WindowsNT\PerfLib and CurrentControlSet\Services), but still remains
in the group it has been added to by the installer.
c) If the machine is restarted (sometimes it is enough to restart IIS), the
problem usually goes away.
d) It is very hard to reproduce the problem. We have observed it for several
months, but still haven't figured out the pattern.

I have searched Google newsgroup archive, KB, MVP-level KB, the Web - but to
no avail. The only post I found on the Russian GotDotNet forum suggested to
swap the order of some lines in code, but this is hardly a reliable
solution.

Any help would be greatly appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top