コード例 #1
0
        private StopwatchScope(MeasurementAction action, string scopeEndString)
        {
            ArgumentUtility.CheckNotNull("action", action);

            _action                = action;
            _scopeEndString        = scopeEndString;
            _lastCheckpointElapsed = TimeSpan.Zero;
            _stopwatch             = Stopwatch.StartNew();
            _disposed              = false;
        }
コード例 #2
0
 public void TimeEqual1500_Disabled()
 {
     MeasurementAction.IsEnabled = false;
     using (var measure = MeasurementAction.StartMeasure(watch =>
     {
         Assert.IsTrue(watch.ElapsedMilliseconds.Equals(0));
     }, true))
     {
         Thread.Sleep(1500);
     }
 }
コード例 #3
0
 public void TimeEqualZero_Enabled()
 {
     MeasurementAction.IsEnabled = true;
     using (var measure = MeasurementAction.StartMeasure(watch =>
     {
         Assert.IsTrue(watch.ElapsedTicks.Equals(0));
     }, false))
     {
         Thread.Sleep(1000);
     }
 }
コード例 #4
0
 public void TimeEqual1500_Enabled()
 {
     MeasurementAction.IsEnabled = true;
     using (var measure = MeasurementAction.StartMeasure(watch =>
     {
         Assert.IsTrue(watch.ElapsedMilliseconds >= 1500 && watch.ElapsedMilliseconds <= 1502);
     }, true))
     {
         Thread.Sleep(1500);
     }
 }
コード例 #5
0
 /// <summary>
 /// Creates a <see cref="StopwatchScope"/> that measures the time, executing the given
 /// <paramref name="action"/> when the scope is disposed or when a <see cref="Checkpoint"/> is reached.
 /// </summary>
 /// <param name="action">The <see cref="MeasurementAction"/> to receive the result. Takes the following arguments:
 /// <c>string context, StopwatchScope scope</c>. Use <see cref="StopwatchScope.ElapsedTotal"/> and
 /// <see cref="StopwatchScope.ElapsedSinceLastCheckpoint"/> to retrieve the elapsed time. When the scope is disposed, the context parameter
 /// is set to the string "end".
 /// </param>
 /// <returns>
 /// A <see cref="StopwatchScope"/> that measures the time.
 /// </returns>
 public static StopwatchScope CreateScope(MeasurementAction action)
 {
     return(new StopwatchScope(action, "end"));
 }