WPF Cross Thread Object Access

后端 未结 3 1062
南旧
南旧 2021-01-24 04:34

I have an issue regarding cross thread calls in WPF.

            foreach (RadioButton r in StatusButtonList)
        {
            StatusType status = null;
             


        
3条回答
  •  情深已故
    2021-01-24 05:00

    I'd rewrite this to:

    r.Dispatcher.Invoke(new Action(delegate()
    {
        status = ((StatusButtonProperties)r.Tag).StatusInformation;
    
        if (AppLogic.CurrentStatus == null || AppLogic.CurrentStatus.IsStatusNextLogical(status.Code))
        {
            r.Background = Brushes.Green;
        }
        else
        {
            r.Background = Brushes.Red;
        }
    
    }));
    

提交回复
热议问题