0

I have a custom control progressbar, that I need to update through another thread.. There doesn't seem to be an Invoke, BeginInvoke, InvokeRequired etc available to a custom control, does anyone have any ideas on how to implement this within the control?

JGU
  • 879
  • 12
  • 14

1 Answers1

0

You will need to look at the Dispatcher.Invoke method to do this. I have a handy method that wraps this functionality for me:

public object RunOnUiThread(Delegate method)
{
    return Dispatcher.Invoke(DispatcherPriority.Normal, method);
}

I use it like this:

UiThreadManager.RunOnUiThread((Action)delegate
{
    // This code will run on the UI thread
});

Note that you will need to use the correct Dispatcher object from the UI thread and not one that is created on a non-UI thread. Please take look at the Dispatcher.Invoke Method page on MSDN for more information on this.

Please let me know if this is not what you were after.

Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • Hi Sheridan, This is close, I would like to wrap them so they preserve the same call signature as seen on other controls, so maybe? public object Invoke(Delegate method) { return Dispatcher.Invoke(DispatcherPriority.Normal, method); } But how would I wrap RequiresInvoke in the same way? – JGU Oct 14 '13 at 15:36
  • Sorry, but what does that mean? – Sheridan Oct 14 '13 at 15:37