Dispose of old connection, if present.

This commit is contained in:
Jared Goodwin 2019-12-22 20:56:29 -08:00
parent 7e6476ed73
commit 2390b67201

View File

@ -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;
};