从非UI线程打开Windows窗体 [英] Open Windows form from non UI thread

查看:121
本文介绍了从非UI线程打开Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何正确地打开窗户,从一个非UI线程形成的?


解决方案

  VAR日=新主题(()=> 
{
变种形式=新YourForm();
form.FormClosing + =(S,E)=> Application.ExitThread ();
form.Show();
Application.Run();
});
th.SetApartmentState(ApartmentState.STA);
th.Start();


How do I properly open a windows form from a non-UI thread?

解决方案

var th = new Thread(() =>
{
    var form = new YourForm();  
    form.FormClosing += (s, e) => Application.ExitThread();
    form.Show();
    Application.Run();
});
th.SetApartmentState(ApartmentState.STA);
th.Start();

这篇关于从非UI线程打开Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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