如何从非GUI线程C#中创建表单 [英] How to Create Form from within non gui thread C#

查看:105
本文介绍了如何从非GUI线程C#中创建表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我从那里我开始在一个单独的线程长时间运行的方法主要GUI。
现在从这个单独的线程中我需要创建并显示一个新的形式。
但是,当我展示这种新形式的所有控件都停留一个窗口说没有响应。

I have my main GUI from where I start a long running method in a separate thread. Now from within this separate thread I need to create and show a new form. But when I show this new form all the controls are stuck an the window says "not responding".

这是解决这个的最好方法?

Which is the best way of solving this ??

关于

托马斯

推荐答案

将创建新的图形用户界面到主GUI类的代码,然后调用主界面的Invoke方法,或引发事件的主界面可以订阅知道什么时候触发新的GUI。如果选择后者,一定要使用InvokeRequired,以确定是否可以打电话直接或创建新的图形用户界面的方法,如果你需要使用一个调用找回到GUI线程来创建新的图形用户界面。

Put the code that creates the new GUI into the main GUI class and then call the main GUI's Invoke method, or raise an event that the main GUI can subscribe to to know when to trigger the new GUI. If you choose the latter, be sure to use InvokeRequired to determine if you can call the method that creates the new GUI directly or if you need to use an Invoke to get back onto the GUI thread to create the new GUI.

这篇关于如何从非GUI线程C#中创建表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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