From f9efaed524378894618c0f85f8d32b5b2daef7f5 Mon Sep 17 00:00:00 2001 From: Archi Date: Thu, 23 Feb 2023 17:20:08 +0100 Subject: [PATCH] Misc --- .../RemoteCommunication.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index d27caa423..7cf7516e7 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -128,12 +128,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } public async ValueTask DisposeAsync() { - // Those are objects that are always being created if constructor doesn't throw exception - MatchActivelySemaphore.Dispose(); - RequestsSemaphore.Dispose(); - WebBrowser.Dispose(); - - // Those are objects that might be null and the check should be in-place + // Dispose timers first so we won't launch new events if (HeartBeatTimer != null) { await HeartBeatTimer.DisposeAsync().ConfigureAwait(false); } @@ -144,6 +139,14 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { MatchActivelyTimer.Dispose(); } } + + // Ensure the semaphores are closed, then dispose the rest + await MatchActivelySemaphore.WaitAsync().ConfigureAwait(false); + await RequestsSemaphore.WaitAsync().ConfigureAwait(false); + + MatchActivelySemaphore.Dispose(); + RequestsSemaphore.Dispose(); + WebBrowser.Dispose(); } internal void OnNewItemsNotification() => ShouldSendAnnouncementEarlier = true;