ShowDialog and Thread

  • Thread starter Thread starter Elp
  • Start date Start date
E

Elp

Hi,

A probably trivial question but i can't figure out the answer myself.

When you call ShowDialog() on a Form to display it modaly, the code located
after the ShowDialog call is not executed until the Form is closed. So it
looks like the thread in which the form runs is frozen or asleep. Of
course, it is not as the form still processes events and you can call
mehtods from this Form, etc. So what really happens when you call
ShowDialog? How come the code after it is not immediately executed? If the
ShowDialog method was just waiting for the form to be closed, the UI thread
would be frozen which is not the case. I'm sure i'm missing something
simple but what?

Thanks.
 
Each program has one UI thread, this thread is responsible for processing
messages for all UI objects.
When you use the ShowDialog(), the dialog is shown in a modal state, you
have told the system that
no other window in your application can receive events. If you want a
modeless dialog, use the Show()
method instead, then both dialogs can receive messages at the same time

The same happens when you use the MessageBox class, this displays a modal
dialog. All other
processing stops until the button is pressed.

Chris
 
Back
Top