views:

85

answers:

3

I recognize this may be a duplicate post, but I want to make sure I ask this question clearly and get an answer based on my wording.

I have a collection of forms which inherit from a common visual element: MainVisualForm. This element provides me a way to know when the form is advancing of stepping backwards. What form comes next in the sequence is dependent on user action.

I currently have this code for one such event as I am testing:

form.OnNextForm += (f, ev) =>
            {
                Parameters.Vehicle = ((VehicleForm)f).SelectedVehicle;
                //FormStack.Push(Parameters.Vehicle == Vehicle.SUV
                //                ? new KeyValuePair<Type, IFormActionBehvaior>(typeof(EntertainmentForm), null)
                //                : new KeyValuePair<Type, IFormActionBehvaior>(typeof(ColorForm), null));
            };

This assignment is followed immediately by ShowDialog() which blocks the user until the Dialog form is closed.

The question is: After the form closes does .NET wait for the EventHandler to complete before running the code which directly follows ShowDialog() or is the handler handled by a different thread?

Thanks very much in advance

+5  A: 

Winforms runs in a single thread - in fact you can't even access it from a second thread without running into trouble. Unless you create a thread yourself (or a BackgroundWorker or anything else that constitutes a thread), you'll only ever have one thread.

Matti Virkkunen
+2  A: 

In simple, .NET Winforms work under a single thread.

+2  A: 

It waits for the event to complete. Events are really just method calls to methods defined somewhere else (aka delegates). After all those complete, the next bit of code after ShowDialog() will run.

Benny Jobigan