How can I get in WPF application, value from slider control in other thread?
To set value I use:
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);
}
}
Method call:
ControlExtensions.InvokeIfRequired(_mw, value => _mw.tb_w3.Text = value, godz_w3);
Using this should work, you’re just extracting the value to the variable
textinstead of assigning it to theTextproperty of what I’ll assume is aTextBox