Process Performance Disabled

I've started getting the following exception when a I call pretty much any method on the 'System.Diagnostics.Process' class.

System.InvalidOperationException: Process performance counter is disabled, so the requested operation cannot be performed.

I need to call 'Process.GetProcessesByName' to detect running instances of Visual Studio before installing TestDriven.NET. There are other ways such as using the GIT (Global Interface Table), but I've gone back to using 'GetProcessesByName' because it seemed to work more consistently on different machines. Now that this method doesn't work on my machine, I'm worried that it might be a common problem.

Has anyone experienced this issue before?  I have found a couple of KB articles, but on one case the fix doesn't work and the other is pretty involved and not the sort of thing you would want to refer users to.  Is there an easier way to fix it?

It looks like Scott Willeke experinced a similar issue when using an old version version of MbUnitPeli has since removed all references to the Process class because of this issue.  The Process FAQ has the following to say about it.

Why does the Process class have a dependency on the performance counter?
The Process class exposes performance information about processes. In order to get performance information about remote processes, we need to query performance information on a remote machine. We used the same code to get performance information about processes on a local machine in Everett. That's why the Process class has a dependency on the performance counter. However, this approach has several problems:

  1. Performance information is not available to a non-admin account, which is not in the Performance Counter Users Group on Windows Server 2003. So the Process class could not get process performance information in this case.
  2. Getting performance data from all the processes on the machine is pretty expensive. The operating system (OS) might load lots of DLLs and it might take seconds to complete. The floppy drive light will be on when the OS tries to find the index for some performance counter.
  3. If the performance counter data was corrupted for any reason, the Process class could throw an exception while trying to convert some raw performance information into DateTime.
  4. The Process class could not be used to get process information on machines without the process performance counter. Performance counters can be disabled in Windows. See the following link for details: http://www.microsoft.com/windows2000/techinfo/reskit/en-us/default.asp?url=/windows2000/techinfo/ reskit/en-us/regentry/94214.asp


The good news is that we have changed the implementation of the Process class in Visual Studio 2005 (our next release, code-named Whidbey). The Process class doesn't have a dependency on performance counter information any more (this is only true for local processes).

This leaves me looking for a good alternative to the Process API in .NET 1.x.

2 Comments

  • We had the same problem when trying to use the Process class to prevent multiple instances of our own application being launched and boy did it take us long to discover the problem as it occured only on certain machines where the performance counters were disabled.



    We came up with a solution that works - unfortunately only for your testing for another instance of your own application and not for another application like you want to do. We basically used a named Mutex to signal between different instances of our application. The named mutex is a system object whose lifetime is bounded by the lifetimes of the Mutex objects

    that represent it. The named mutex would be created by the first instance of our application process. When the second SanQuote process comes along, it creates its mutex and waits for zero seconds for the first instance to signal that it is finished. Because the first instance is still running, this will

    not happen and the second instance therefore knows that there is already an instance of application running.

  • Thanks Jamie for this article. it has given me a lead to solve my problem.

Comments have been disabled for this content.