From cc3053719c0b6afdd39ce64afdccb1d62e3e916f Mon Sep 17 00:00:00 2001 From: Jan Korf Date: Sun, 22 May 2022 15:46:30 +0200 Subject: [PATCH] Make socket ConnectionLost run in a separate task to prevent issue with long running/exceptions in the handler --- CryptoExchange.Net/Sockets/SocketConnection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CryptoExchange.Net/Sockets/SocketConnection.cs b/CryptoExchange.Net/Sockets/SocketConnection.cs index bbca717..b4efe6e 100644 --- a/CryptoExchange.Net/Sockets/SocketConnection.cs +++ b/CryptoExchange.Net/Sockets/SocketConnection.cs @@ -301,7 +301,7 @@ namespace CryptoExchange.Net.Sockets if (!lostTriggered) { lostTriggered = true; - ConnectionLost?.Invoke(); + _ = Task.Run(() => ConnectionLost?.Invoke()); } while (ShouldReconnect) @@ -390,7 +390,7 @@ namespace CryptoExchange.Net.Sockets if (lostTriggered) { lostTriggered = false; - _ = Task.Run(() => ConnectionRestored?.Invoke(time.HasValue ? DateTime.UtcNow - time.Value : TimeSpan.FromSeconds(0))).ConfigureAwait(false); + _ = Task.Run(() => ConnectionRestored?.Invoke(time.HasValue ? DateTime.UtcNow - time.Value : TimeSpan.FromSeconds(0))); } break;