views:

29

answers:

1

In my application, each thread handle a Form, and its events shall executed within the thread handling the Form.

Is there a way to handle events for a specific System.Windows.Form instance? Application.Run doesn't fit my design, and Application.DoEvents process events for each Form instantiated by the application.

+1  A: 

You'll run into a bit of an issue, as all of your Form's will be on the UI Thread, and thus the events are not "free threaded". The suggested method to handle this is for long-running tasks to be pushed to a BackgroundWorker or perhaps to a ThreadPool. You would then use Invoke to execute tasks on the UI Thread, making the handling of actions multithreaded while the UI is still single threaded.

sixlettervariables
I'm rendering on two windows using OpenGL. Rendering happens on different threads (one thread for each Form which holds the rendering result).Calling Application.Run after having started rendering threads, all events are handled in another thread (main thread): this mean I have to synch rendering threads with the main thread (caller of Application.DoEvents or Application.Run)?
Luca
In terms of Windows events, yes those will only come in on a single thread. So you will need to coordinate with whatever thread handles `DoEvents`.
sixlettervariables