public async Task <bool> ExecuteAsync(Tray tray, CancellationTokenSource cts) { Part part = null; tray.Status = TrayStatus.TS_Measuring; while (true) { if (cts.IsCancellationRequested) { break; } if (_ac.IsOffline) { break; } if (_ac.Mark.Value) { part = await _selector.ExecuteAsync(tray, cts); if (part == null) { break; } } if (_ac.IsOffline || cts.IsCancellationRequested) { part.Status = PartStatus.PS_Idle; break; } SetupPartParams(tray, part); bool success = await _mesPartActivity.ExecuteAsync(part, cts).ConfigureAwait(false); if (success) { continue; } part.Status = PartStatus.PS_Error; // TODO 中断执行 选择处理路径 _ac.Cont_Evt.WaitOne(); // 测量失败跳转 retry - true, next - false, next tray - null if (_ac.Mark == null) { break; } if (!_ac.Success) { return(false); } } return(true); }
public async void CycleProcess(Rack _rack) { if (!CmmOnline) { return; } Working = true; StartedEvent?.Invoke(this, null); _cts = new CancellationTokenSource(); Tray tray = null; bool success; while (true) { if (_cts.IsCancellationRequested) { break; } tray = await _traySelector.ExecuteAsync(_rack, _cts); if (tray == null) { break; } if (_cts.IsCancellationRequested) { tray.Status = TrayStatus.TS_Idle; break; } SetupTray(tray); success = await _rootActivity.ExecuteAsync(CurrentTray, _cts).ConfigureAwait(false); if (!success) { // 报告错误并跳出循环 tray.Status = TrayStatus.TS_Error; break; } tray.Status = TrayStatus.TS_Measured; } // 如果运行到这里,设置离线可能会断不开连接 // 在cmmControl中增加标志位,是否还在连接 //if (!CmmOnline) //{ // _cmmControl.Offline(); //} Working = false; StoppedEvent?.Invoke(this, null); _offlineWaitFlag.Set(); }