Created
June 9, 2011 15:26
-
-
Save prabirshrestha/1016973 to your computer and use it in GitHub Desktop.
Stopwatch helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Diagnostics; | |
| public class StopWatchHelper : IDisposable | |
| { | |
| private readonly bool _displayTime; | |
| private readonly Stopwatch _stopwatch; | |
| public StopWatchHelper() | |
| : this(true) | |
| { | |
| } | |
| public StopWatchHelper(bool displayTime) | |
| { | |
| _displayTime = displayTime; | |
| _stopwatch = new Stopwatch(); | |
| _stopwatch.Start(); | |
| } | |
| public void Dispose() | |
| { | |
| _stopwatch.Stop(); | |
| if (_displayTime) | |
| { | |
| Console.WriteLine(_stopwatch.Elapsed); | |
| } | |
| } | |
| public Stopwatch Stopwatch | |
| { | |
| get { return _stopwatch; } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment