Skip to content

Instantly share code, notes, and snippets.

@thebirk
Created October 6, 2021 11:17
Show Gist options
  • Save thebirk/680eb541cd0682cbd7fbc71bb3e5230e to your computer and use it in GitHub Desktop.
Save thebirk/680eb541cd0682cbd7fbc71bb3e5230e to your computer and use it in GitHub Desktop.
public class DisposableStopwatch : Stopwatch, IDisposable
{
public delegate string OnStopDelegate(TimeSpan time);
private readonly OnStopDelegate _onStop;
public DisposableStopwatch(OnStopDelegate onStop)
{
_onStop = onStop;
Start();
}
public void Dispose()
{
Stop();
Debug.WriteLine(_onStop(Elapsed));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment