diff --git a/src/prometheus-net.DotNetRuntime/DotNetRuntimeStatsCollector.cs b/src/prometheus-net.DotNetRuntime/DotNetRuntimeStatsCollector.cs index 211b7ac..0ae63ec 100644 --- a/src/prometheus-net.DotNetRuntime/DotNetRuntimeStatsCollector.cs +++ b/src/prometheus-net.DotNetRuntime/DotNetRuntimeStatsCollector.cs @@ -20,7 +20,7 @@ internal sealed class DotNetRuntimeStatsCollector : private readonly CollectorRegistry _metricRegistry; private readonly Options _options; - private readonly object _lockInstance = new (); + private static readonly object LockInstance = new (); private readonly CancellationTokenSource _ctSource = new(); private readonly Task _recycleTask; private bool _disposed = false; @@ -34,7 +34,7 @@ internal DotNetRuntimeStatsCollector(ServiceProvider serviceProvider, CollectorR var metrics = Prometheus.Metrics.WithCustomRegistry(_metricRegistry); _listenerGlobalOpts = DotNetEventListener.GlobalOptions.CreateFrom(_options, metrics); - lock (_lockInstance) + lock (LockInstance) { if (Instances.ContainsKey(_metricRegistry)) { @@ -143,7 +143,7 @@ public void Dispose() } finally { - lock (_lockInstance) + lock (LockInstance) { Instances.Remove(_metricRegistry); }