【问题标题】:WPF - Open Message Box while another Message Box is openWPF - 在另一个消息框打开时打开消息框
【发布时间】:2021-03-16 19:05:03
【问题描述】:

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

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));

【问题讨论】:

    标签: wpf async-await task messagebox


    【解决方案1】:

    MessageBox.Show 调用MessageBox function (winuser.h)

    remarks你可以阅读:

    如果在对话框存在时创建消息框,请使用对话框句柄作为hWnd 参数。 hWnd 参数不应标识子窗口,例如对话框中的控件。

    但您无法获取消息框的hWnd

    你最好为此创建一个自定义窗口。

    【讨论】:

    • 很遗憾它不能按我想要的方式工作,但还是谢谢你:)
    猜你喜欢
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 2018-11-16
    相关资源
    最近更新 更多