diff --git a/StabilityMatrix.Core/Helper/CodeTimer.cs b/StabilityMatrix.Core/Helper/CodeTimer.cs index f881c4c5..4121af7d 100644 --- a/StabilityMatrix.Core/Helper/CodeTimer.cs +++ b/StabilityMatrix.Core/Helper/CodeTimer.cs @@ -11,6 +11,7 @@ public class CodeTimer : IDisposable private readonly string name; private readonly Stopwatch stopwatch; + private bool isDisposed; private CodeTimer? ParentTimer { get; } private List SubTimers { get; } = new(); @@ -97,6 +98,9 @@ public class CodeTimer : IDisposable public void Dispose() { + if (isDisposed) + return; + stopwatch.Stop(); // Remove ourselves from the stack @@ -119,6 +123,7 @@ public class CodeTimer : IDisposable SubTimers.Clear(); } + isDisposed = true; GC.SuppressFinalize(this); } }