From d092be1eb22bd7a357b3f01b76a57d8385327091 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 27 Feb 2026 14:23:22 -0500 Subject: [PATCH] Fix Dispose lock on GLPriceCache --- .../MarketDataLib/Cache/GLPriceCache.cs | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/MarketData/MarketDataLib/Cache/GLPriceCache.cs b/MarketData/MarketDataLib/Cache/GLPriceCache.cs index 0377f1f..bbc3603 100644 --- a/MarketData/MarketDataLib/Cache/GLPriceCache.cs +++ b/MarketData/MarketDataLib/Cache/GLPriceCache.cs @@ -15,6 +15,10 @@ namespace MarketData.Cache // -- Singleton ------------------------------------------------------------ private static readonly object instanceLock = new object(); private static GLPriceCache instance = null; + // -- Disposal ------------------------------------------------------------- + private volatile bool disposed = false; + + private int refreshInProgress = 0; /// /// @@ -52,10 +56,6 @@ namespace MarketData.Cache // return int.TryParse(configured, out int parsed) && parsed > 0 ? parsed : @default; } - // -- Disposal ------------------------------------------------------------- - private volatile bool disposed = false; - private int refreshInProgress = 0; - // -- Constructor ---------------------------------------------------------- private GLPriceCache() { @@ -63,14 +63,17 @@ namespace MarketData.Cache } /// - /// Dispoal + /// Dispose /// public void Dispose() { - Dispose(true); - GC.SuppressFinalize(this); + Dispose(true); + GC.SuppressFinalize(this); } + /// + /// Dispose + /// protected virtual void Dispose(bool disposing) { if (disposed) return; @@ -78,21 +81,15 @@ namespace MarketData.Cache if (disposing) { - Timer timerToDispose; + Timer timerToDispose = null; lock (instanceLock) { - timerToDispose = refreshTimer; - refreshTimer = null; - instance = null; + timerToDispose = refreshTimer; + refreshTimer = null; + instance = null; } - // Block until any in-flight tick completes before disposing - using (ManualResetEventSlim waited = new ManualResetEventSlim(false)) - { - if (timerToDispose != null) - timerToDispose.Dispose(waited.WaitHandle); - waited.Wait(TimeSpan.FromSeconds(10)); - } - + // Dispose timer immediately; no blocking wait + timerToDispose?.Dispose(); MDTrace.WriteLine(LogLevel.DEBUG, "[GLPriceCache:Dispose] Disposed."); } }