public void Send(string command, string onResult = null) { lock (_lockObject) { _uiContext.Send( x => { CommunicationLog.Insert(0, "grbl <=" + command); if (CommunicationLog.Count > 500) { CommunicationLog.Remove(CommunicationLog.Last()); } }, null); } OnCommunicationLogUpdated(); var cmd = new Command { Data = command, CommandOnResult = onResult }; _commandPreProcessor.Process(ref cmd); switch (cmd.Type) { case RequestType.Realtime: Send(cmd); break; case RequestType.System: { lock (_lockObject) { if (!SystemCommands.DataInQueue(cmd.Data, 3)) { SystemCommands.Add(command); } } break; } default: { lock (_lockObject) { ManualCommands.Add(command); } break; } } }