Hi I am trying to make a global class that I can use in my projects, I intend to use this as my default template, I am a newbie so please be patient 😉
Stopwatch Masterstopwatch = new Stopwatch();
#if DEBUG
private static void ApplicationLogStart()
{
StartTime = DateTime.Now;
Masterstopwatch.Start();
String eventName = "Program Loaded";
String errorDetails = "Program has started Succesfully";
DataLogEntry(eventName, errorDetails);
}
private static void ApplicationLogclosing()
{
String eventName = "Program is closing";
String errorDetails = "Program has closed Succesfully";
DataLogEntry(eventName, errorDetails);
StopTime = DateTime.Now;
Masterstopwatch.Stop();
Benchmark(StartTime,StopTime,Masterstopwatch.Elapsed);
}
#endif
I suspect that I am fundimently flawed in my design as I want the Stopwatch Masterstopwatch = new Stopwatch(); to be declared globally without using a method, I suspect that this is not posible, but I need to ask
Thanks
Sounds like you need the Singleton Pattern.
If you declare a wrapper around stopwatch as follows you can use it anywhere in your app and access the same instance of a Stopwatch.