private void RefreshTaskStatus() { try { if (null == formOutput) { return; } ListView lv = formOutput.GetListViewHandle(); if (lv == null) { return; } switch (taskFresh.iTaskStep) { case 0: { taskFresh.htTimer.Start(); taskFresh.iTaskStep = 10; } break; case 10: if (taskFresh.htTimer.TimeUp(0.1)) { try { if (lv != null) { Action action = () => { if (lv.Items.Count != listTask.Count) { lv.Items.Clear(); foreach (TaskUnit item in listTask) { ListViewItem lvi = lv.Items.Add(item.strName); lvi.UseItemStyleForSubItems = false; lvi.SubItems.Add(""); lvi.SubItems.Add(""); lvi.SubItems.Add(""); lvi.SubItems.Add(""); lvi.SubItems.Add(""); } } lv.BeginUpdate(); for (int i = 0; i < listTask.Count; i++) { #region TaskRefresh if (listTask[i].taskInfo.bTaskOnGoing) { lv.Items[i].SubItems[1].Text = "OnGoing"; lv.Items[i].SubItems[1].BackColor = Color.Green; lv.Items[i].SubItems[2].Text = "Step: " + listTask[i].taskInfo.iTaskStep.ToString(); lv.Items[i].SubItems[3].Text = "CT: " + listTask[i].taskInfo.htTimer.Duration.ToString("0.0") + " s"; lv.Items[i].SubItems[4].Text = ""; } else if (listTask[i].taskInfo.bTaskFinish) { lv.Items[i].SubItems[1].Text = "Finish"; lv.Items[i].SubItems[1].BackColor = lv.BackColor; lv.Items[i].SubItems[2].Text = "Step: " + listTask[i].taskInfo.iTaskStep.ToString(); lv.Items[i].SubItems[3].Text = " "; lv.Items[i].SubItems[4].Text = ""; } else if (listTask[i].taskInfo.bTaskAlarm) { lv.Items[i].SubItems[1].Text = "Alarm"; lv.Items[i].SubItems[1].BackColor = Color.Red; lv.Items[i].SubItems[2].Text = "Step: " + listTask[i].taskInfo.iTaskStep.ToString(); lv.Items[i].SubItems[3].Text = " "; if (listTask[i].taskInfo.iTaskStep > 0) { lv.Items[i].SubItems[4].Text = "报警解除后,任务将继续执行"; } else { lv.Items[i].SubItems[4].Text = "报警解除后,任务重新执行"; } } else { lv.Items[i].SubItems[1].Text = "Idle"; lv.Items[i].SubItems[1].BackColor = lv.BackColor; lv.Items[i].SubItems[2].Text = "Step: " + listTask[i].taskInfo.iTaskStep.ToString(); lv.Items[i].SubItems[3].Text = " "; lv.Items[i].SubItems[4].Text = ""; } if (bPreOnGoingList[i] != listTask[i].taskInfo.bTaskOnGoing) { if (listTask[i].taskInfo.bTaskOnGoing) { listTask[i].taskInfo.htTimer.Start(); } } bPreOnGoingList[i] = listTask[i].taskInfo.bTaskOnGoing; #endregion } lv.EndUpdate(); }; lv.Invoke(action); } } catch { //MessageBox.Show(ex.Message); } taskFresh.iTaskStep = 20; } break; case 20: if (true) { taskFresh.iTaskStep = 0; } break; default: break; } } catch (Exception) { } }