Ejemplo n.º 1
0
        public static TResult Watch <TResult>(string watchingCall, Func <TResult> func)
        {
            TResult local;

            if (string.IsNullOrEmpty(watchingCall) || !startTime.HasValue)
            {
                return(func());
            }
            Stopwatch stopwatch = new Stopwatch();

            try
            {
                stopwatch.Start();
                local = func();
            }
            finally
            {
                stopwatch.Stop();
                if (watchedResult == null)
                {
                    watchedResult = new WatchedResult();
                }
                watchedResult.Results.Add(new WatchedResult.WatchingResult(watchingCall, stopwatch.ElapsedMilliseconds));
            }
            return(local);
        }
Ejemplo n.º 2
0
 public static void Watch(string watchingCall, Action action)
 {
     if (string.IsNullOrEmpty(watchingCall) || !startTime.HasValue)
     {
         action();
     }
     else
     {
         Stopwatch stopwatch = new Stopwatch();
         try
         {
             stopwatch.Start();
             action();
         }
         finally
         {
             stopwatch.Stop();
             if (watchedResult == null)
             {
                 watchedResult = new WatchedResult();
             }
             watchedResult.Results.Add(new WatchedResult.WatchingResult(watchingCall, stopwatch.ElapsedMilliseconds));
         }
     }
 }
Ejemplo n.º 3
0
        public WatchedResult StopWatcher()
        {
            WatchedResult result = new WatchedResult();

            if (startTime.HasValue && (watchedResult != null))
            {
                TimeSpan span = (TimeSpan)(DateTime.Now - startTime.Value);
                result.ElapsedTime = span.TotalMilliseconds;
                result.Results.AddRange(watchedResult.Results);
            }
            startTime     = null;
            watchedResult = null;
            return(result);
        }
Ejemplo n.º 4
0
 public static PerformanceWatcher StartNewWatcher()
 {
     startTime     = new DateTime?(DateTime.Now);
     watchedResult = new WatchedResult();
     return(new PerformanceWatcher());
 }