父窗口和线程亲和性

发布于 2024-07-25 05:07:07 字数 439 浏览 13 评论 0原文

我有一个 WinForms 应用程序,我想在其中执行一些长时间运行的操作,例如想象一下 Explorer 并行复制 2 个大文件。 对于每个长时间运行的操作,我都会启动一个单独的 UI 线程(其中包括泵送消息/Application.Run/Application.ExitThread),在其中创建 IProgressDialog

我想知道 - 由于 Windows 的线程亲和性 - 将主窗体的句柄打包到 HandleRef 并将其作为进度对话框的所有者/父级传递(位于不同的 UI 线程上)是否合法? 我没有从辅助 UI 线程访问主窗口的句柄(调试模式下没有跨线程异常),只是将其传递给本机函数。

谢谢。

I'm having a WinForms application where I would like to perform some long-running operations, e.g. imagine Explorer copying 2 big files in parallel. For each of those long-running operations I'm starting a separate UI thread (which includes pumping messages/Application.Run/Application.ExitThread) where I create an instance of the IProgressDialog.

I'm wondering - due to the thread affinity of windows - is it legal to package the main form's handle into a HandleRef and pass it as owner/parent of the progress dialog, which is on a different UI thread? I'm not accessing the main window's handle from the secondary UI thread (no cross-thread exceptions in debug mode), only passing it on to the native function.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

谷夏 2024-08-01 05:07:07

是的,没关系。 Windows允许不同线程的窗口有父子关系。

Yes, that's fine. Windows allows windows of different threads to have a parent/child relationship.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文