在 MDI 容器中将每个子窗体作为单独的线程运行

发布于 2024-12-12 11:43:07 字数 69 浏览 0 评论 0原文

是否可以在单独的线程上运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜柠檬 2024-12-19 11:43:07

我无法从问题中看出您是否意识到您所提出的解决方案的奇异性。如果这个答案完全没有切中要害,我深表歉意。

我假设您希望应用程序具有响应能力。您不希望在一种表单正在工作时其他表单“挂起”。

然而,每个表单拥有不同的 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.

霊感 2024-12-19 11:43:07

不可以。

任何 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.

╰ゝ天使的微笑 2024-12-19 11:43:07

这篇 MSDN 论坛帖子表示表单可以在单独的线程中运行。不过,我不知道它是否适用于子 MDI 表单。但技术很简单:

Thread thread = new Thread( () =>
   {
         var yourForm = new YourForm();
         Application.Run(yourForm);
   });
thread.ApartmentState = ApartmentState.STA;
thread.Start();

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:

Thread thread = new Thread( () =>
   {
         var yourForm = new YourForm();
         Application.Run(yourForm);
   });
thread.ApartmentState = ApartmentState.STA;
thread.Start();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文