VS 2005, C# 2.0, .NET 2.0/3.0, Win2003
I'm trying to install a set of performance counters for a MultiInstance. I noticed that some system performance counter categories manage to keep a "total" alive even when there are no other instances. ASP.NET Apps 2.0.50727 is an example.
So I've been trying to duplicate this. I created the following routine in an Installer class which I then add to a Custom Action in a setup project.
public override void Install(System.Collections.IDictionary stateSaver)
{
//Debugger.Break();
CounterCreationData data = new CounterCreationData("ZCounter", "ZCtrHelp", PerformanceCounterType.NumberOfItems32);
PerformanceCounterCategory.Create("ZCategory", "ZCatHelp", PerformanceCounterCategoryType.MultiInstance, new CounterCreationDataCollection(new CounterCreationData[] { data }));
PerformanceCounter counter = new PerformanceCounter();
counter.CategoryName = "ZCategory";
counter.CounterName = "ZCounter";
counter.InstanceName = "ZTotal";
counter.InstanceLifetime = PerformanceCounterInstanceLifetime.Global;
counter.ReadOnly = false;
counter.RawValue = 0;
base.Install(stateSaver);
}
If I uncomment the Debugger.Break()
line, and step through, I can see the counter is actually created with the right instance name, and Visual Studio Server Explorer shows the instance along with the InstanceLifetime set to Global. I do not call the RemoveInstance() method in the setup program.
Nevertheless, a few seconds after the setup program completes, that instance disappears from the Performance Monitor and from the VS Server Explorer. How do I make it stick? Or can I?