InvokeRequired in wpf [duplicate] InvokeRequired in wpf [duplicate] wpf wpf

InvokeRequired in wpf [duplicate]


In WPF, the Invoke method is on the dispatcher, so you need to call Dispatcher.Invoke instead of Invoke. Also, there is no InvokeRequired property, but the dispatcher has a CheckAccess method (for some reason, it's hidden in intellisense). So your code should be:

delegate void ParametrizedMethodInvoker5(int arg);void log_left_accs(int arg){    if (!Dispatcher.CheckAccess()) // CheckAccess returns true if you're on the dispatcher thread    {        Dispatcher.Invoke(new ParametrizedMethodInvoker5(log_left_accs), arg);        return;    }    label2.Text= arg.ToString();}


In WPF use the CheckAccess method instead of InvokeRequired

if (!CheckAccess()) {   // On a different thread  Dispatcher.Invoke(() => log_left_accs(arg));  return;}