From 2390b67201bec4a8a8e5acb24fa1da8c2ec9db16 Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Sun, 22 Dec 2019 20:56:29 -0800 Subject: [PATCH] Dispose of old connection, if present. --- ScreenCast.Core/Sockets/CasterSocket.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ScreenCast.Core/Sockets/CasterSocket.cs b/ScreenCast.Core/Sockets/CasterSocket.cs index 735b1ed7..728dc450 100644 --- a/ScreenCast.Core/Sockets/CasterSocket.cs +++ b/ScreenCast.Core/Sockets/CasterSocket.cs @@ -47,13 +47,18 @@ namespace Remotely.ScreenCast.Core.Sockets public async Task Connect(string host) { + if (Connection != null) + { + await Connection.StopAsync(); + await Connection.DisposeAsync(); + } Connection = new HubConnectionBuilder() .WithUrl($"{host}/RCDeviceHub") .AddMessagePackProtocol() .Build(); ApplyConnectionHandlers(); - + await Connection.StartAsync(); } @@ -134,7 +139,6 @@ namespace Remotely.ScreenCast.Core.Sockets Connection.Closed += (ex) => { Logger.Write($"Connection closed. Error: {ex?.Message}"); - Environment.Exit(0); return Task.CompletedTask; };