如何在 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);