When I show a message box from within an async method, the z-Order of the new message box may be wrong, and the box might be missed by the user.
Consider the following code:
private async void btnShowMessage_Click(object sender, EventArgs e)
{
await Task.Delay(3000);
MessageBox.Show("Test");
}
Run this application, click the ShowMessage-Button and activate some different window. When the message is shown, it can appear in the background. Since it correctly blocks interaction with the main window, to the user it seems that the application is hanging.
I know, that this can be prevented by explicitly supplying an owner to the Show()
-method.
Anyways, I was wondering whether there is a more generic solution to this problem
(actually, I was expecting the ExecutionContext
to handle this).