Hi,
I encountered a problem trying to write a code that does the following:
1. Main GUI thread invokes a delegate using BeginInvoke.
2. A secondery thread (from the application's managed thread pool)
starts executing and BeginInvoke returns.
3. Main GUI thread remains responsive while the secondery thread
executes in the background.
4. Secondery thread finishes its execution.
5. Main GUI thread is notified of the completion of the action, and an
event is raised / a callback function executes IN THE MAIN GUI THREAD.
To phase 4 everything works fine; The main thread is responsive and the
secondery thread executes in the background.
Now my problem pops - How can I notify the main thread that the
secondery thread finished its execution, so that it could run a method?
I tried using the callback method parameter of the BeginInvoke method,
but from a little check I performed, it seems that the code executes in
the secondery thread and not in the main GUI thread. If my program was
written in C++, I could have used a window message to notify my main
thread of the completion of the action. The .NET framework does not
contain a PostMessage method to add a message to the main thread's
message pump, and I would really like to avoid using p/invoke. What is
the .NET way to do it?
Many thanks,
John Tiffany.