private static void HeartbeatThread(DiffBotSerial serial) { try { var ct = serial.CancellationToken(); var stopwatch = new Stopwatch(); ControllerInput.ResetAlive(); while (!ct.IsCancellationRequested) { stopwatch.Restart(); ControllerInput.SendKeepAlive(); var wait = heartbeatInterval - stopwatch.Elapsed; if (wait > TimeSpan.Zero) ct.WaitHandle.WaitOne(wait); } } catch (Exception e) { Log.Error("Exception in Heartbeat Thread", e); } }
private static void WriteThread(DiffBotSerial serial) { try { var ct = serial.CancellationToken(); while (true) serial.SendPacket(packetQueue.Take(ct)); } catch (OperationCanceledException) {} catch (Exception e) { Log.Error("Exception in Write Thread", e); } }