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;
            }
        }

 

posted @ 2023-03-20 15:34  lingmin210  阅读(56)  评论(0编辑  收藏  举报