using System; using System.Diagnostics; namespace Sony.Filtr.Tasks.EventSource { internal class DisposableDuration : IDisposable { public readonly Stopwatch sw; private readonly Action StopAction; public DisposableDuration(Action startAction, Action stopAction) { sw = new Stopwatch(); sw.Start(); this.StopAction = stopAction; startAction(); } #region IDisposable Support private bool disposedValue = false; protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { sw.Stop(); this.StopAction(sw.Elapsed.TotalMilliseconds); } disposedValue = true; } } public void Dispose() { Dispose(true); } #endregion } }