From 72bf6d204f88807e8da9ad0f643004c90848101d Mon Sep 17 00:00:00 2001 From: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com> Date: Mon, 27 May 2024 11:31:00 +0200 Subject: [PATCH] Fix issues with restarting P2P client (#167) --- src/KKManager.Updater/Sources/TorrentUpdater.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/KKManager.Updater/Sources/TorrentUpdater.cs b/src/KKManager.Updater/Sources/TorrentUpdater.cs index ade2f17..3674042 100644 --- a/src/KKManager.Updater/Sources/TorrentUpdater.cs +++ b/src/KKManager.Updater/Sources/TorrentUpdater.cs @@ -21,10 +21,11 @@ namespace KKManager.Updater.Sources public static class TorrentUpdater { private static ClientEngine _client; + private static bool _eventsInitialized; private static async Task GetClient() { // Only runs once the first time - if (_client == null) + if (!_eventsInitialized) { // When waking up from sleep restart all running torrents so they re-announce and such // If sleep happened for a while then the torrent can be stuck for a long time otherwise @@ -53,6 +54,7 @@ private static async Task GetClient() #if DEBUG MonoTorrent.Logging.LoggerFactory.Register(className => new MonoTorrent.Logging.TextLogger(Console.Out, className)); #endif + _eventsInitialized = true; } if (_client == null || _client.Disposed) @@ -347,6 +349,7 @@ public void Move(FileInfo targetpath) public static async Task Stop() { await DisposeClient(); + _client = null; } public static async Task Start()