// (c) 2007 Richard Grimes // www.grimes.demon.co.uk using System; using System.Diagnostics; class Server { const string catName = "Data Generator"; const string catHelp = "Generates random sample data"; const string ctrName = "# Connected Clients"; const string ctrHelp = "The number of clients connected to the server"; static void Main(string[] args) { if (args.Length > 0) { // Delete category if (PerformanceCounterCategory.Exists(catName)) { PerformanceCounterCategory.Delete(catName); } return; } if (!PerformanceCounterCategory.Exists(catName)) { // Create new counter if it does not exist CounterCreationDataCollection ccdc = new CounterCreationDataCollection(); CounterCreationData ccd = new CounterCreationData(ctrName, ctrHelp, PerformanceCounterType.NumberOfItems32); ccdc.Add(ccd); PerformanceCounterCategory.Create( catName, catHelp, PerformanceCounterCategoryType.SingleInstance, ccdc); Console.WriteLine("Category created, re-run the application"); return; } } }