AcUtils
A high performance abstraction layer for AccuRev
AcStopWatch.cs
Go to the documentation of this file.
1 
16 using System;
17 using System.Diagnostics;
18 
19 namespace AcUtils
20 {
24  [Serializable]
25  public sealed class AcStopWatch
26  {
27  #region class variables
28  public delegate void ElapsedTimeHandler(string elapsedTime);
29  private ElapsedTimeHandler _elapsedTimeHandler;
30  [NonSerialized] private Stopwatch _stopwatch;
31  #endregion
32 
37 
38  public AcStopWatch(ElapsedTimeHandler elapsedTimeHandler)
39  {
40  _elapsedTimeHandler = elapsedTimeHandler;
41  }
42 
46  public void Start()
47  {
48  _stopwatch = Stopwatch.StartNew();
49  }
50 
54  public void Stop()
55  {
56  if (_elapsedTimeHandler != null)
57  {
58  AcDuration ts = _stopwatch.Elapsed;
59  _elapsedTimeHandler(ts.ToString());
60  }
61  }
62  }
63 
68 
80 
86  public struct AcStopWatchMarker : IDisposable
87  {
88  private AcStopWatch _stopwatch;
89 
93  public AcStopWatchMarker(AcStopWatch stopwatch)
94  {
95  _stopwatch = stopwatch;
96  _stopwatch.Start();
97  }
98 
103  public void Dispose()
104  {
105  _stopwatch.Stop();
106  }
107  }
108 }
void Dispose()
Calls the client's ElapsedTimeHandler at the closing brace of the using statement. Implemented by calling AcStopWatch::Stop.
Definition: AcStopWatch.cs:103
delegate void ElapsedTimeHandler(string elapsedTime)
void Start()
Set the stopwatch to zero and begin measuring elapsed time.
Definition: AcStopWatch.cs:46
Wrapper around TimeSpan so we can return our own formatted elapsed time string and still sort correct...
Definition: AcDuration.cs:25
void Stop()
Call the client's ElapsedTimeHandler with the elapsed time as a formatted string in days...
Definition: AcStopWatch.cs:54
Makes the using statement available for AcStopWatch objects. Adapted from Profiling with Stopwatch by...
Definition: AcStopWatch.cs:86
Determine the amount of time a task takes to run.
Definition: AcStopWatch.cs:25
string ToString(string format, IFormatProvider provider)
The ToString implementation.
Definition: AcDuration.cs:140
AcStopWatchMarker(AcStopWatch stopwatch)
Constructor to initialize and start the stopwatch. Implemented by calling AcStopWatch::Start.
Definition: AcStopWatch.cs:93
AcStopWatch(ElapsedTimeHandler elapsedTimeHandler)
Constructor that takes an ElapsedTimeHandler.
Definition: AcStopWatch.cs:38