是否可以在不阻塞所有表单的情况下使用 ShowDialog? [英] Is it possible to use ShowDialog without blocking all forms?

查看:34
本文介绍了是否可以在不阻塞所有表单的情况下使用 ShowDialog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我能解释得足够清楚.我有我的主窗体 (A),它使用 form.Show() 打开 1 个子窗体 (B),使用 form.Show() 打开第二个子窗体 (C).现在我希望子窗体 B 使用 form.ShowDialog() 打开一个窗体 (D).当我这样做时,它也会阻塞表单 A 和表单 C.有没有办法打开模态对话框并且只让它阻止打开它的表单?

I hope I can explain this clearly enough. I have my main form (A) and it opens 1 child form (B) using form.Show() and a second child form (C) using form.Show(). Now I want child form B to open a form (D) using form.ShowDialog(). When I do this, it blocks form A and form C as well. Is there a way to open a modal dialog and only have it block the form that opened it?

推荐答案

如果您在与 A 和 C 不同的线程上运行表单 B,则 ShowDialog 调用将仅阻止该线程.显然,这当然不是一项微不足道的工作投资.

If you run Form B on a separate thread from A and C, the ShowDialog call will only block that thread. Clearly, that's not a trivial investment of work of course.

只需在单独的线程上运行 Form D 的 ShowDialog 调用,您就可以让对话框完全不阻塞任何线程.这需要相同类型的工作,但要少得多,因为您的应用主线程只会运行一个表单.

You can have the dialog not block any threads at all by simply running Form D's ShowDialog call on a separate thread. This requires the same kind of work, but much less of it, as you'll only have one form running off of your app's main thread.

这篇关于是否可以在不阻塞所有表单的情况下使用 ShowDialog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆