This project has moved and is read-only. For the latest updates, please go here.

MessageBox: Blocking Application if the app is not in the foreground

Dec 4, 2010 at 12:08 AM
Edited Dec 4, 2010 at 12:13 AM

I have this long running process in an application, and typical use is that a user clicks on the run process, he will get a message popped up that this is going to take long time. This part works fine. At this point will click ok and switches to some other app like outlook. A minute or later another message pops up saying the process is complete. Here is the problem, that if the user clicks the taskbar to activate the app, but the remains unresponsive, as the messagebox is active. But this messagebox remains in the background.

Another common scenario is when I am debugging on laptop with one one screen. When I switch to visual studio and run movenext in the debugger, visual studio is the active application, and the actual WPF app remains in the background.

I think it needs to check for if the application is active, and if not it should activate the app. If not some other workaround should be there for the problem.

Thanks for your help

BP

Dec 4, 2010 at 1:02 AM

This is not a problem with the MessageBox control.  This is the default behavior of how Window objects work in an application.  You cannot activate a Window, main application window or not, when a MessageBox is open, because Messagebox controls are opened using a ShowDialog, meaning nothing can recieve focus until the messagebox is closed.  This is true for both the Microsoft MessageBox and the toolkit's MessageBox.  You mentioned the MessageBox is in the background.  Do you mean behind the Window?

As far as Visual Studio debugging goes, this too is expected behavior.  While debugging I do not expect you want the application to suddenly pop up in front of your debug session.  This is also default Visual Studio behavior, and will beave this way regardless of using message boxes.

In either case I would personally take a different approach to your application usability.  I am assuming you are locking out the UI while this process is occuring.  You should run your process in a seperate thread and use the BusyIndicator control to let the user know something is running.  This way the user can still use other parts of your application while the process is finished.  Then when it is completed you could notify your user of its completion.

Dec 4, 2010 at 1:17 AM
Thanks for the quick reply Brian.
The problem I think is that it is not finding it's owner and thus when the application is activated it is not coming into foreground. Since it is showed as dialog, one cannot get focus on other windows. Also it does not show in the taskbar, to find it. On this case one can only activate the mesagebox using alt-tab as it is listed there. This does not happen with the standard windows messagebox.


From: [email removed]
To: [email removed]
Date: Fri, 3 Dec 2010 17:02:26 -0800
Subject: Re: MessageBox: Blocking Application if the app is not in the foreground [wpftoolkit:237101]

From: brianlagunas
This is not a problem with the MessageBox control. This is the default behavior of how Window objects work in an application. You cannot activate a Window, main application window or not, when a MessageBox is open, because Messagebox controls are opened using a ShowDialog, meaning nothing can recieve focus until the messagebox is closed. This is true for both the Microsoft MessageBox and the toolkit's MessageBox. You mentioned the MessageBox is in the background. Do you mean behind the Window?
As far as Visual Studio debugging goes, this too is expected behavior. While debugging I do not expect you want the application to suddenly pop up in front of your debug session. This is also default Visual Studio behavior, and will beave this way regardless of using message boxes.
In either case I would personally take a different approach to your application usability. I am assuming you are locking out the UI while this process is occuring. You should run your process in a seperate thread and use the BusyIndicator control to let the user know something is running. This way the user can still use other parts of your application while the process is finished. Then when it is completed you could notify your user of its completion.
Read the full discussion online.
To add a post to this discussion, reply to this email (wpftoolkit@discussions.codeplex.com@discussions.codeplex.com)
To start a new discussion for this project, email wpftoolkit@discussions.codeplex.com@discussions.codeplex.com
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Dec 4, 2010 at 1:25 AM

That would make sense, if it couldn't find an owner then it would probably show behind the window.  Regretfully i am unable to duplicate the behavior.  I typed up a simple application but could not recreate the issue.  Would it be possible for you to create a sample app that duplicates the issue?