private static void StreamWorker_DoWork(object sender, DoWorkEventArgs e) { while (true) { Task <string> receiveTask = Connection.ConnectionReader.ReadLineAsync(); //won't raise exception on disconnect, will set exception prop and IsCompleted prop while (!receiveTask.IsCompleted) { if (GCodeProvider.HasLine && (CurrentGRBLBuffer + GCodeProvider.PeekLineLength() + 1 < Properties.Settings.Default.GrblBufferSize)) { string line = GCodeProvider.GetLine(); CurrentGRBLBuffer += line.Length + 1; ActiveCommands.Enqueue(line); Connection.ConnectionWriter.WriteLine(line); Console.WriteLine($"sent {line}"); } System.Threading.Thread.Sleep(25); } if (receiveTask.Exception == null) { string receivedLine = receiveTask.Result; Console.WriteLine($"received {receivedLine}"); if (!string.IsNullOrWhiteSpace(receivedLine) && !HandleReceivedLine(receivedLine)) { streamWorker.ReportProgress(0, receivedLine); } } } }
public void AddCommand(IEngineCommand c) { ActiveCommands.Enqueue(c); }