在BackgroundWorker中创建表单的实例 [英] Creating an instance of a form in a BackgroundWorker
本文介绍了在BackgroundWorker中创建表单的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在BackgroundWorker中创建表单的新实例.我注意到,这样做时,新启动的表单将冻结.
I want to create a new instance of a form in a BackgroundWorker. I've noticed that when I do this, the newly launched form freezes.
为什么此表格冻结?我该如何解决?
Why does this form freeze? How can I get around this?
推荐答案
它冻结了,因为您在错误的线程中创建了表单-后台线程中没有运行事件循环.
It's freezing because you're creating the form in the wrong thread - there's no event loop running in the background thread.
您应仅在UI线程中创建或触摸UI元素. BackgroundWorker
为此提供了一些挂钩,或者您可以使用Control.Invoke
/BeginInvoke
.
You should only create or touch UI elements in the UI thread. BackgroundWorker
provides some hooks for this, or you can use Control.Invoke
/BeginInvoke
.
这篇关于在BackgroundWorker中创建表单的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文