在 MDI 容器中将每个子窗体作为单独的线程运行
是否可以在单独的线程上运行 MDI 窗体的每个子窗体?如果是这样,您能否给出一些代码和示例如何设置?
谢谢!
Is it possible to run each child form of a MDI form on a separate thread? If so, can you please give some codes and example how to setup this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我无法从问题中看出您是否意识到您所提出的解决方案的奇异性。如果这个答案完全没有切中要害,我深表歉意。
我假设您希望应用程序具有响应能力。您不希望在一种表单正在工作时其他表单“挂起”。
然而,每个表单拥有不同的 GUI 线程并不是人们通常实现这一目标的方式。我不知道这是否可能。
您仍然只有一个线程处理所有图形(也称为“GUI 线程”),但所有耗时的工作应立即卸载到另一个线程(又称为工作线程)。这样应用程序就能保持响应。
我建议你看看这个视频。适用与否,4-6分钟之内,你应该知道这是否是你正在寻找的答案。
Stephen Toub 的 DNRTV 剧集
另一种可能是您询问如何显示一个没有模态的表单。
I can't tell from the question wether you are aware of the exotic nature of the solution you are proposing. I apologize if this answer completely misses the mark.
I assume that you want responsiveness in your application. That you don't want other forms to "hang" while one form is doing work.
However, having a different GUI thread per form is not how one usually achieves this. I don't know if it is even possible.
You will still have only one thread handling all the graphics (aka "the GUI Thread"), but all time consuming work should be immediately offloaded to another thread (aka worker thread). That way the app remains responsive.
I suggest you check out this video. Applicable or not, within 4-6 minutes, you should know wether this is the answer you are looking for.
DNRTV episode with Stephen Toub
Another possibility is that you are asking about how to display a form without it being modal.
不可以。
任何 GUI 活动都必须在主线程上发生。
处理可以在单独的线程中完成,在这种情况下,请尝试在子表单中使用
BackgroundWorker
。No.
Any GUI activity has to happen on the main thread.
Processing can be done in a separate thread, in which case, try using the
BackgroundWorker
in your child forms.这篇 MSDN 论坛帖子表示表单可以在单独的线程中运行。不过,我不知道它是否适用于子 MDI 表单。但技术很简单:
This MSDN forum post says that forms can be run in separate threads. I don't know if it's applicable to child MDI forms, though. But the technique is simple enough: