private async void StartPollingLoop() { int tried = 0; while (!(_runningTokenSource?.IsCancellationRequested ?? false) && _inboundReader != null) { var reader = _inboundReader; try { await reader.LoadAsync(FbnsPacketDecoder.PACKET_HEADER_LENGTH); } catch (Exception ex) { PrintException("StartPollingLoop", ex); Log("StartPollingLoop: " + ex.Message + "\n" + ex.Source + "\n"); // Connection closed (most likely) return; } try { var packet = await FbnsPacketDecoder.DecodePacket(reader); await OnPacketReceived(packet); } catch (Exception ex) { PrintException("StartPollingLoop22", ex); Log("StartPollingLoop22: " + ex.Message + "\n" + ex.Source + "\n"); if (tried > 3) { Shutdown(); Start(); break; } tried++; if (tried <= 3) { await Task.Delay(10000); } } } }
private async void StartPollingLoop() { while (Running) { var reader = _inboundReader; Packet packet; try { await reader.LoadAsync(FbnsPacketDecoder.PACKET_HEADER_LENGTH); packet = await FbnsPacketDecoder.DecodePacket(reader); } catch (Exception e) { if (Running) { DebugLogger.LogException(e, false); Restart(); } return; } await OnPacketReceived(packet); } }