开发者

Are events in WinForms fired asynchronously?

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开发者_如何学JAVA 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


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜