I'm trying to run code from worker threads by invoking it on the main UI thread; however, I don't have an instance of the main form or any controls (nor do I want one in the class where the threaded code is running).
I've found things like the built-in System.Windows.Forms.MethodInvoker
delegate, which has an Invoke()
method. I figured if I instantiated my MethodInvoker
on the main thread and then called its Invoke()
method on the worker thread, everything would work as I wanted. However, simple debugging demonstrates that the invoked method still runs on the worker thread.
I can't find any documentation on MethodInvoker.Invoke()
. There isn't even a "Members" link on MSDN for it, yet it exists. The only thing I've found, which states what I already know, is the accepted answer in this SO post:
Using C# MethodInvoker.Invoke() for a GUI app... is this good?
So, my questions are:
How can I invoke a method on the main thread without an instance of the main form or other UI elements?
Why isn't the
MethodInvoker.Invoke()
method documented anywhere? What am I missing?