Deleting and recreating perf-counter categories - 10-01-2004 , 07:13 PM
If I programatically delete and recreate my performance counter categories
with each application session, I'm unable to call certain methods on the
actual perf counters themselves, like NextValue() -- these methods throw an
InvalidOperationException with "Category not found" as the error message.
But, all works fine if the counter category exists when the application
starts -- and I dont subsequently delete and recreate it. What gives?
As it stands, I have my app check to see if its category exists, and
recreate it only if it doesn't, or if it doesn't contain all of the perf
counter types that are presently defined. If it needs to recreate the
category I have to warn the user for them to restart the app so that I can
call NextValue() without failure...
Isn't this strange?
RE: Deleting and recreating perf-counter categories - 10-08-2004 , 11:32 AM
Generally you should create performance counter categories when the
application is installed and not at run time. Performance counter are
fairly unreliable if you create a category and then immediately try to
access counters on it. Having said that calling
PerformanceCounter.CloseSharedResources() might fix the majority of your
problems. PerformanceCounter caches a lot of data(what categories exist on
the machine) and CloseSharedResources clears the cache.
I would still recomend that you install the category when the app is
installed because it is likely you will run into other problems.
Ryan Byington [MS]
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
|Thread Tools||Search this Thread|