Browse Source

Fix codetimer corruption when disposed multiple times

pull/324/head
Ionite 1 year ago
parent
commit
81bff73266
No known key found for this signature in database
  1. 5
      StabilityMatrix.Core/Helper/CodeTimer.cs

5
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<CodeTimer> 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);
}
}

Loading…
Cancel
Save