public static void Main(string[] args) { Console.WriteLine("This example will show how to write multithreaded console."); var MyComputation = new LongComputation(); StopwatchDelegate GotTime = e => { Console.WriteLine("time: " + e.TotalMilliseconds + "ms"); }; GotTime.Measure( delegate { MyComputation.Start(); Console.WriteLine(); Console.WriteLine("Press enter to stop current computation."); Console.ReadLine(); MyComputation.Stop(); Console.WriteLine("Value: " + MyComputation.Current.Value); } ); Console.WriteLine(); Console.WriteLine("Press enter to exit."); Console.ReadLine(); }
/// <summary> /// This method will print to console on what is going to be done, then it will measure the action and /// after the action returns the time elapsed in milliseconds will be printed to the console. /// </summary> /// <param name="e"></param> /// <param name="h"></param> /// <returns></returns> public static TimeSpan Measure(this string e, Action h) { StopwatchDelegate s = (StopwatchConsoleHint)e; return(s.Measure(h)); }