public const string CounterCategoryName = "CounterName"; public const string CounterCategoryNameHelp = "Description"; public const string CounterName_WS001 = "WS001"; public const string CounterName_WS001_Help = "Description of the WS001"; public void Start() { Console.WriteLine("UtilCounter Start ---------------------"); if (!PerformanceCounterCategory.Exists(CounterCategoryName)) { CounterCreationDataCollection counters = new CounterCreationDataCollection(); counters.Add(new CounterCreationData(CounterName_WS001, CounterName_WS001_Help, PerformanceCounterType.ElapsedTime)); PerformanceCounterCategory.Create( CounterCategoryName, CounterCategoryNameHelp, PerformanceCounterCategoryType.SingleInstance,counters); } // Test the Performance counters if(PerformanceCounterCategory.CounterExists(CounterName_WS001,CounterCategoryName)) { PerformanceCounter pc = new PerformanceCounter(CounterCategoryName, CounterName_WS001,false); pc.RawValue = 56; while(true) { Thread.Sleep(3000); pc.RawValue = 20; Console.WriteLine("pc.RawValue ... "); } } Console.WriteLine("UtilCounter End --------------------"); }
Advertisements
Leave a Reply