嗨,我正在为程序测试一些东西,每次测试完成时,都会显示一个新的消息框。问题在于,在此之前我关闭消息框后,只会打开一个新的消息框。我尝试将消息框放到新任务中,但是那也不起作用...
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调用MessageBox函数(winuser.h)。
在备注中,你可以阅读:
如果在出现对话框时创建消息框,请使用对话框的句柄作为
hWnd
参数。该hWnd
参数不应标识子窗口,例如对话框中的控件。
但是你无法获得hWnd
消息框的。
你最好为此创建一个自定义窗口。
遗憾的是,它无法按我想要的方式工作,但仍然谢谢您:)