tags:

views:

100

answers:

2

Hello

This is a very similar problem to This one, sadly that one was never answered either.

I have a MDI Main forum that hosts several children forms. One of them does a long calculation and throws an exception if an error occurs (all work is done on the same thread). I then try to inform the user of an error with an messagebox, however it doesn't appear (but steals focus from the MDI Main, so the application is completely unresponsive).

The beheviour changes slightly if I call Application.DoEvents() (evil I know, but this is a last resort thing). Then the forms remain completely active and the messagebox only appears after I change active application (Alt+Tab) to something else and then back again.

What can I do to make sure the messagebox will be visible? I have already tried passing both, active child and MDI Main as parameter to the MessageBox.Show method. It doesn't change the behaviour.

To clarify: the messagebox is a part of the child form, however at this point I am willing to show it in any way that doesn't break the application. The messagebox should be modal, but it should be visible so it can be acknowledged by the user.

A: 

Is the MessageBox shown in the MainForm or as part of the ChildForms? If the MessageBox is in the child Forms maybe you could pass an event back to the MainForm and open the MessageBox there.

Holli
A: 

The problem is that messageboxes tend to be modal. In this instance I think that you'd do far better to use a delegate or an event with a handler in your main MDI code. That way your main application displays the message boxes. You can easily redefined an EventArgsType if you wish to pass whatever information that you require.

ChrisBD