That's good news, thanks.
I worked around this by using a different name for the category and the
service. This is fine for now.
Now I'm hitting another problem. After I Delete the category and re-Create
it, I then add the new counters using code as follows:
// Remove any hanging or previously-created category information
if (PerformanceCounterCategory.Exists( _perfMonCategoryName ))
{
PerformanceCounterCategory.Delete( _perfMonCategoryName );
}
if (_perfMonCategory != null)
{
ApplicationLog.Log( LogType.INFO, 0,
"PerfMon Statistics are being replaced for " +
_perfMonCategoryName);
foreach (PerformanceCounter pc in _perfMonData)
{
pc.Close();
}
PerformanceCounter.CloseSharedResources();
_perfMonData.Clear();
}
// Register the current process with PerfMon as a new category of
counters, with
// one entry in a list of counters per Statistic for the process
CounterCreationDataCollection newCounters = new
CounterCreationDataCollection();
foreach (Statistic st in _statistics)
{
CounterCreationData newCounter = new CounterCreationData(st.PerfMonName,
st.PerfMonName,
PerformanceCounterType.NumberOfItems32 );
newCounters.Add(newCounter);
}
_perfMonCategory = PerformanceCounterCategory.Create(
_perfMonCategoryName,
ColorPaletteHelpString,
newCounters);
// Export the initial values for each counter
foreach (Statistic st in _statistics)
{
PerformanceCounter newData = new PerformanceCounter(
_perfMonCategoryName,
st.Name,
false ); // writable
ApplicationLog.Log( LogType.INFO, 0,
"PerfMon counter:" +
newData.CounterType + " " + newData.CounterHelp);
newData.RawValue = st.iValue;
st.Counter = newData;
_perfMonData.Add( newData );
}
}
In the debugger, the categoryHelp on _perfMonCategory shows up as null
although I am passing in a string ColorPaletteHelpString. In addition, the
Log call to dump newData.CounterType and newData.CounterHelp fails with
exception "Category does not exist", although I can see it in the debugger
after the .Create call just above.
I am beginning to suspect that this area of .Net 1.1 is what is sometimes
referred to as a "bug farm". Is this one also expected to be fixed in .Net
2.0? Are there any other known bugs I need to look out for?
Another comment - it looks to me like the PerformanceCounterCategory class
may use a single named mutex "netfxperf.1.0" to control access to all .Net
custom counters. The SWI team would probably be interested in this, since
these are trivial to squat on and deny access to legitimate users, without
proper security controls.

Signature
Steve Townsend
Lava Trading
> >I am attempting to instrument several existing Windows service applications
> > (written in C#) using the PerformanceCounter* classes in .Net FW 1.1 SP1.
[quoted text clipped - 65 lines]
>
> David
Steve Townsend - 06 Jul 2005 15:29 GMT
OK, I have a red face. There's a bug in the code I posted here - once I
fixed this the code is working better and publishing data OK. The exception
text is misleading (it's the counter name on PerformanceCounter.Create that's
at fault, not the category) but I still could have checked further. When I
ran under .Net 2.0, the Fwk provides a better exception, and the fix was then
trivial.
Thanks for your help.

Signature
Steve Townsend
Lava Trading
> That's good news, thanks.
>
[quoted text clipped - 147 lines]
> >
> > David