Skip to content

Commit b78b52b

Browse files
authored
Port Dispose method changes from elasticsearch-net (#14)
1 parent 36caa70 commit b78b52b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Elastic.Transport/Diagnostics/Diagnostic.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ internal class Diagnostic<TState, TStateEnd> : Activity, IDisposable
2525
private readonly DiagnosticSource _source;
2626
private TStateEnd _endState;
2727
private readonly bool _default;
28+
private bool _disposed;
2829

2930
private Diagnostic() : base("__NOOP__") => _default = true;
3031

@@ -45,8 +46,19 @@ internal set
4546
}
4647
}
4748

49+
protected override void Dispose(bool disposing)
50+
{
51+
if (_disposed) return;
52+
53+
if (disposing)
54+
{
55+
//_source can be null if Default instance
56+
_source?.StopActivity(SetEndTime(DateTime.UtcNow), EndState);
57+
}
58+
59+
_disposed = true;
4860

49-
//_source can be null if Default instance
50-
protected override void Dispose(bool disposing) => _source?.StopActivity(SetEndTime(DateTime.UtcNow), EndState);
61+
base.Dispose(disposing);
62+
}
5163
}
5264
}

0 commit comments

Comments
 (0)