Example #1
0
        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();
        }
Example #2
0
        public static TimeSpan Measure(this StopwatchDelegate e, Action h)
        {
            var s = new Stopwatch();

            s.Start();
            h();
            s.Stop();
            e(s.Elapsed);

            return(s.Elapsed);
        }
        public static IDisposable Measure(this StopwatchDelegate h)
        {
            var s = new Stopwatch();

            s.Start();

            return(new Measure_IDisposable
            {
                Handler =
                    delegate
                {
                    s.Stop();
                    h(s.Elapsed);
                }
            });
        }
        /// <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));
        }