468,170 Members | 2,149 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,170 developers. It's quick & easy.

How is it possible to show two modal message boxes in the same thread?

OK this has me perplexed, puzzled and bamboozled!

I have a remoting service which I displayed a message box in. I then
wondered what would happen if a client made a call to the service
while the message box was being displayed. Since the call comes in on
a different thread the client call was not blocked. This seemed to
make sense to me.

Next I thought, what will happen when the client calls into the server
if I try to use a delegate to call back onto the UI thread? To my mind
I thought I should be blocked, but I was able to perform work on the
UI thread while the message box was displayed. So finally, I thought I
wonder what happens if I then also try an display another message box
on the UI thread and sure enough I was able to display two modal
message boxs on the UI thread (I put the current thread ID in the
message boxes just to make sure it was on the same thread).

I don't understand this behaviour as I think a modal dialog should
block a thread... But I am clearly wrong, I just don't know why?!

andrew
www.vbusers.com
Nov 16 '05 #1
3 2474
A MessageBox isn't really the same thing as a modal dialog. You can keep
poping up MessageBoxes until theres loads stacked up on the screen ;)

to show a modal dialog look at Form.ShowDialog and show a form.

we*******@vbusers.com (Andrew Baker) wrote in
news:c1**************************@posting.google.c om:
OK this has me perplexed, puzzled and bamboozled!

I have a remoting service which I displayed a message box in. I then
wondered what would happen if a client made a call to the service
while the message box was being displayed. Since the call comes in on
a different thread the client call was not blocked. This seemed to
make sense to me.

Next I thought, what will happen when the client calls into the server
if I try to use a delegate to call back onto the UI thread? To my mind
I thought I should be blocked, but I was able to perform work on the
UI thread while the message box was displayed. So finally, I thought I
wonder what happens if I then also try an display another message box
on the UI thread and sure enough I was able to display two modal
message boxs on the UI thread (I put the current thread ID in the
message boxes just to make sure it was on the same thread).

I don't understand this behaviour as I think a modal dialog should
block a thread... But I am clearly wrong, I just don't know why?!

andrew
www.vbusers.com


Nov 16 '05 #2
Keep in mind that neither modal dialogs or message boxes (which are
essentially a type of modal dialog) really block the current thread. The
thread is processing a message loop the whole time -- if it were blocked
with respect to the parent window, the window wouldn't be able to redraw
itself as you move the modal dialog over top of it.

The way I think of it is that each thread running a message loop has a
stack of modal dialogs. Any time a modal dialog is opened (including message
boxes), it's pushed onto the stack. All of these dialogs share the same
message pump, but that pump only allows certain messages (i.e. non-input
related) to reach windows which are not the top-most in the stack (e.g.
paint messages can get through but click events and such don't). When the
moda dialog is closed, it's popped off the stack and the next one down
becomes the "active" dialog.

So, in your experiment, you should have noticed that even though you had two
message boxes up on the same UI thread, one was "active" and the other
couldn't be closed until the active one was closed.

Ken
"Andrew Baker" <we*******@vbusers.com> wrote in message
news:c1**************************@posting.google.c om...
OK this has me perplexed, puzzled and bamboozled!

I have a remoting service which I displayed a message box in. I then
wondered what would happen if a client made a call to the service
while the message box was being displayed. Since the call comes in on
a different thread the client call was not blocked. This seemed to
make sense to me.

Next I thought, what will happen when the client calls into the server
if I try to use a delegate to call back onto the UI thread? To my mind
I thought I should be blocked, but I was able to perform work on the
UI thread while the message box was displayed. So finally, I thought I
wonder what happens if I then also try an display another message box
on the UI thread and sure enough I was able to display two modal
message boxs on the UI thread (I put the current thread ID in the
message boxes just to make sure it was on the same thread).

I don't understand this behaviour as I think a modal dialog should
block a thread... But I am clearly wrong, I just don't know why?!

andrew
www.vbusers.com

Nov 16 '05 #3
Thanks Ken,

that's an excellent explaination...

andrew
"Ken Kolda" <ke*******@elliemae-nospamplease.com> wrote in message news:<u6*************@tk2msftngp13.phx.gbl>...
Keep in mind that neither modal dialogs or message boxes (which are
essentially a type of modal dialog) really block the current thread. The
thread is processing a message loop the whole time -- if it were blocked
with respect to the parent window, the window wouldn't be able to redraw
itself as you move the modal dialog over top of it.

The way I think of it is that each thread running a message loop has a
stack of modal dialogs. Any time a modal dialog is opened (including message
boxes), it's pushed onto the stack. All of these dialogs share the same
message pump, but that pump only allows certain messages (i.e. non-input
related) to reach windows which are not the top-most in the stack (e.g.
paint messages can get through but click events and such don't). When the
moda dialog is closed, it's popped off the stack and the next one down
becomes the "active" dialog.

So, in your experiment, you should have noticed that even though you had two
message boxes up on the same UI thread, one was "active" and the other
couldn't be closed until the active one was closed.

Ken
"Andrew Baker" <we*******@vbusers.com> wrote in message
news:c1**************************@posting.google.c om...
OK this has me perplexed, puzzled and bamboozled!

I have a remoting service which I displayed a message box in. I then
wondered what would happen if a client made a call to the service
while the message box was being displayed. Since the call comes in on
a different thread the client call was not blocked. This seemed to
make sense to me.

Next I thought, what will happen when the client calls into the server
if I try to use a delegate to call back onto the UI thread? To my mind
I thought I should be blocked, but I was able to perform work on the
UI thread while the message box was displayed. So finally, I thought I
wonder what happens if I then also try an display another message box
on the UI thread and sure enough I was able to display two modal
message boxs on the UI thread (I put the current thread ID in the
message boxes just to make sure it was on the same thread).

I don't understand this behaviour as I think a modal dialog should
block a thread... But I am clearly wrong, I just don't know why?!

andrew
www.vbusers.com

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Rich Wahl | last post: by
3 posts views Thread by dp | last post: by
4 posts views Thread by Drew Lettington | last post: by
3 posts views Thread by Earl Teigrob | last post: by
4 posts views Thread by Brian Henry | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.