Improved console disposing and closing
This commit is contained in:
parent
fd01787dfb
commit
01729b982d
1 changed files with 13 additions and 5 deletions
|
@ -99,6 +99,9 @@ public class ServerConsole : IDisposable
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if(Cancellation.IsCancellationRequested)
|
||||
break;
|
||||
|
||||
if (e is WebSocketException)
|
||||
Logger.Warn($"Lost connection to daemon server websocket: {e.Message}");
|
||||
else
|
||||
|
@ -112,7 +115,6 @@ public class ServerConsole : IDisposable
|
|||
}
|
||||
|
||||
await OnDisconnected.Invoke();
|
||||
await WebsocketStream.Close();
|
||||
}
|
||||
|
||||
public async Task Close()
|
||||
|
@ -120,8 +122,8 @@ public class ServerConsole : IDisposable
|
|||
if(!Cancellation.IsCancellationRequested)
|
||||
Cancellation.Cancel();
|
||||
|
||||
if(WebsocketStream != null)
|
||||
await WebsocketStream.Close();
|
||||
if (WebSocket.State == WebSocketState.Open)
|
||||
await WebSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None);
|
||||
}
|
||||
|
||||
private string[] GetMessageCache()
|
||||
|
@ -134,9 +136,15 @@ public class ServerConsole : IDisposable
|
|||
{
|
||||
MessageCache.Clear();
|
||||
|
||||
await OnDisconnected.ClearSubscribers();
|
||||
await OnStateChange.ClearSubscribers();
|
||||
await OnStatsChange.ClearSubscribers();
|
||||
await OnNewMessage.ClearSubscribers();
|
||||
|
||||
if (WebSocket.State == WebSocketState.Open)
|
||||
await WebsocketStream.Close();
|
||||
await WebSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None);
|
||||
|
||||
WebSocket.Dispose();
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue