public void Run() { IsRunning = true; try { using (var socket = new ResponseSocket()) { socket.Options.Linger = TimeSpan.Zero; socket.Bind(clientAddress.ZmqAddress + ":" + GlobalConstants.TcpIpPort.Heartbeat); var timoutCounter = 0; while (!stopRunning) { var request = socket.ReceiveNetworkMsg(TimeSpan.FromSeconds(1)); if (request == null) { timoutCounter++; if (timoutCounter == 10) { Application.Current?.Dispatcher.Invoke(() => ServerVanished?.Invoke()); break; } } else if (request.Type == NetworkMessageType.HeartbeatRequest) { timoutCounter = 0; var heartbeatRequest = (HeartbeatRequest)request; socket.SendNetworkMsg(new HeartbeatResponse(heartbeatRequest.SessionId)); } } } } catch { // Ignored } IsRunning = false; }