public async Task <bool> ReloadConnection(string wsURL) { using (reloadMutex) { this.cleanupConnection(); webSocket = new ClientWebSocket(); try { await webSocket.ConnectAsync(new Uri(wsURL), CancellationToken.None); } catch (Exception e) { this.CloseCB(e.ToString()); return(false); } listener = new WebSocketListener( webSocket, MsgCB, CloseCB ); ConnectedCB(); return(true); } }
void cleanupConnection() { if (webSocket != null) { webSocket.Dispose(); webSocket = null; } if (listener != null) { listener.Dispose(); listener = null; } }