/// <summary> /// Add the busy object to the list to stop it /// </summary> /// <param name="Obj"></param> void RegisterBusyComponent(IServiceSystem Obj) { if (!BusyComponents.Contains(Obj)) { BusyComponents.Add(Obj); } }
/// <summary> /// Start a specified alignment process asynchronously, all alignment process will be started by this common function /// </summary> /// <param name="AlignHandler"></param> async void StartAlignmentProc(AlignmentBase AlignHandler) { if (GetSystemState() == SystemState.IDLE) { SetSystemState(SystemState.BUSY); LastMessage = new MessageItem(MessageType.Normal, string.Format("Start running {0}...", AlignHandler)); // to calculate time costs DateTime alignStarts = DateTime.Now; try { // add alignement class to busy components list BusyComponents.Add(AlignHandler); // pause the auto-fetching process of instrument AlignHandler.Args.PauseInstruments(); // run actual alignment process await Task.Run(() => { AlignHandler.Start(); }); } catch (Exception ex) { this.LastMessage = new MessageItem(MessageType.Error, string.Format("{0} Error, {1}", AlignHandler, ex.Message)); PostErrorMessageToFrontEnd(this.LastMessage.Message); } finally { try { AlignHandler.Args.ResumeInstruments(); } catch (Exception ex) { LastMessage = new MessageItem(MessageType.Error, string.Format("Unable to resume auto-fetching process of {0}, {1}", AlignHandler.Args.Instrument, ex.Message)); BusyComponents.Remove(AlignHandler); } } LastMessage = new MessageItem(MessageType.Normal, string.Format("{0} complete, costs {1}s", AlignHandler, (DateTime.Now - alignStarts).TotalSeconds)); SetSystemState(SystemState.IDLE); } }