protected virtual async Task ExecuteConnectAsync() { var hasError = true; var isDisposed = true; while (hasError) { try { if (isDisposed) { currentSocket = new MessageWebSocket(); currentSocket.MessageReceived += SocketMessageReceived; currentSocket.Closed += SocketClosed; } await currentSocket.ConnectAsync(uri); hasError = false; } catch (Exception e) { isDisposed = e is ObjectDisposedException; await Task.Delay(Interval); } } Debug.WriteLine("Socket #\{currentSocket.GetHashCode()} created");