wpf不在主线程的话放到主线程执行
/// <summary> /// 刷新页面状态 /// </summary> /// <param name="overViewState"></param> /// <param name="strValue"></param> private void BindStates(OverViewState overViewState, string strValue) { if (!Dispatcher.CheckAccess()) // 不在主线程的话放到主线程 { this.Dispatcher.Invoke(new Action(delegate { BindStates(overViewState, strValue); })); return; } switch (overViewState) { case OverViewState.ReactTemp: this.txtTempReact.Text = strValue + "℃"; break; case OverViewState.ReagentTemp: this.txtTempReagent.Text = strValue + "℃"; break; case OverViewState.TubeCount: txtTubeLeft.Text = strValue; txtTubeLeft.Foreground = (strValue == "充足") ? Brushes.Green : Brushes.Red; break; case OverViewState.WashState: txtWashLeft.Text = strValue; txtWashLeft.Foreground = (strValue == "充足") ? Brushes.Green : Brushes.Red; break; case OverViewState.WastTubeState: txtWashLeft.Text = strValue; txtWashLeft.Foreground = (strValue == "正常") ? Brushes.Green : Brushes.Red; break; default: break; } }