【问题标题】:Get value from a controls in other thread从其他线程中的控件获取值
【发布时间】:2013-01-03 11:44:34
【问题描述】:

如何在 WPF 应用程序中获取其他线程中滑块控件的值?

设置我使用的值:

public static class ControlExtensions
    {
        public static void InvokeIfRequired(this Control control, Action action)
        {
            if (System.Threading.Thread.CurrentThread != control.Dispatcher.Thread)
                control.Dispatcher.Invoke(action);
            else
                action();
        }
        public static void InvokeIfRequired<T>(this Control control, Action<T> action, T parameter)
        {
            if (System.Threading.Thread.CurrentThread != control.Dispatcher.Thread)
                control.Dispatcher.Invoke(action, parameter);
            else
                action(parameter);
        }
    }

方法调用:

ControlExtensions.InvokeIfRequired(_mw, value => _mw.tb_w3.Text = value, godz_w3);

【问题讨论】:

    标签: c# wpf multithreading invoke


    【解决方案1】:

    使用它应该可以工作,您只是将值提取到变量 text 而不是将其分配给我假设是 TextBoxText 属性

    string text;
    _mw.InvokeIfRequired(value => text = _mw.Text);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-04
      • 1970-01-01
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多