From ea213a32c35d7498f4711f689b61dc777715a925 Mon Sep 17 00:00:00 2001 From: Matthew Endsley Date: Tue, 2 Feb 2021 07:07:52 -0800 Subject: [PATCH] Only join threads if we were active --- .../ThreadLimitedUdpConnectionListener.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs b/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs index 7e2da60..98f8301 100644 --- a/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs +++ b/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs @@ -359,15 +359,19 @@ namespace Hazel.Udp.FewerThreads try { this.socket.Close(); } catch { } try { this.socket.Dispose(); } catch { } + bool wasActive = this.isActive; this.isActive = false; this.receiveQueue?.CompleteAdding(); this.sendQueue?.CompleteAdding(); - this.reliablePacketThread.Join(); - this.sendThread.Join(); - this.receiveThread.Join(); - this.processThreads.Join(); + if (wasActive) + { + this.reliablePacketThread.Join(); + this.sendThread.Join(); + this.receiveThread.Join(); + this.processThreads.Join(); + } this.receiveQueue?.Dispose(); this.receiveQueue = null; -- 2.39.5