WPF - 在另一个消息框打开时打开消息框

WPF - Open Message Box while another Message Box is open

您好,我正在为我的程序测试一些东西,每次测试完成时都会显示一个新的消息框。 问题是我之前关闭消息框后,只会打开一个新的消息框。 我尝试将消息框放入新任务中,但这也不起作用...

Task.Run(() => System.Windows.MessageBox.Show(
                dirs[directory] + " is done, it took " + stopwatch.Elapsed,
                "Done with " + dirs[directory],
                System.Windows.MessageBoxButton.OK,
                System.Windows.MessageBoxImage.Information,
                System.Windows.MessageBoxResult.OK,
                System.Windows.MessageBoxOptions.ServiceNotification));

我还尝试使方法异步并等待 Task.Run,也没有成功

 await Task.Run(() => System.Windows.MessageBox.Show(
                dirs[directory] + " is done, it took " + stopwatch.Elapsed,
                "Done with " + dirs[directory],
                System.Windows.MessageBoxButton.OK,
                System.Windows.MessageBoxImage.Information,
                System.Windows.MessageBoxResult.OK,
                System.Windows.MessageBoxOptions.ServiceNotification));

MessageBox.Show invokes MessageBox function (winuser.h).

remarks 您可以阅读:

If you create a message box while a dialog box is present, use a handle to the dialog box as the hWnd parameter. The hWnd parameter should not identify a child window, such as a control in a dialog box.

但是你无法获取消息框的hWnd

你最好为此创建自定义 window。