父窗口和线程亲和性
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,没关系。 Windows允许不同线程的窗口有父子关系。
Yes, that's fine. Windows allows windows of different threads to have a parent/child relationship.