无法从线程启动winForm [英] can't start winForm from a thread

查看:89
本文介绍了无法从线程启动winForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从线程启动winForm,但是当我这样做时,表单显示但没有任何标签被加载(背景应该是白色)并且表单被冻结.

I am trying to start a winForm from a thread, but when i do so, the form show but none of the labels are loaded ( the background where they should be is white ) and the form is frozen.

我已经用其他winForms尝试过了,我知道它可以正常工作,但似乎仍然不起作用?有人遇到过这个问题吗?

I've tried it with some other winForms that i know that work just fine and it still doesn't seem to work ? Has anyone encountered this problem ?

我知道这个问题含糊不清,但实际上我没有任何特定的代码可以帮助您理解问题.

I know the question is vague but there isn't really any specific code that I could give to help understand the problem.

推荐答案

这是因为Message Loop仅在UI线程上运行.并且在任何其他线程中创建控件或窗口时,它都无法访问该消息循环.因此,无法处理用户输入.

That is because the Message Loop runs on UI thread only. And when a control or window is created in any other thread, it cannot access that message loop. And thus, cannot process user input.

要解决此问题,请尝试从UI线程创建一个窗口,然后从该窗口创建一个线程,以执行您想在其他线程中执行的任何操作.

To solve this, try creating a window from UI thread and create a thread from that window to do whatever you want to do in different thread.

这篇关于无法从线程启动winForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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