public void Disconnect() { var wait = new AutoResetEvent(false); _heartbeatTimer.Dispose(wait); wait.WaitOne(); _ws.Close(); _notifyMsgState.Enabled = false; _notifyMsgState.Notification.WaitOne(); }