STAThread与非STAThread框架 [英] STAThread vs non STAThread framework

查看:65
本文介绍了STAThread与非STAThread框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的STAThread属性存在很大问题。我正在使用XNA框架

与WinForms连接。 XNA正在使用非STAThread。我有一个显示CommonDialog表单的

问题,例如打开文件对话框。因为XNA框架,我不能将主方法声明为STAThread。是

有没有办法在表单中声明表单或某些方法作为STAThread(我认为
认为Form中的方法可以调用OpenFileDialog)也许我是

错了。


你知道我怎么解决问题吗?


谢谢。

RK。

Hi All,
I have a big problem with STAThread attribute. I''m using XNA framework
connected with WinForms. XNA is working in non STAThread. I have a
problem with displaying CommonDialog forms e.g. OpenFileDialog. I
can''t declare a main method as STAThread because of XNA framework. Is
there any way to declare form or some method in form as STAThread (I
think that a method from Form can invoke OpenFileDialog) maybe I''m
wrong.

Do you know how I can resolve a problem?

Thanks.
RK.

推荐答案

" rafalK" < kr ******* @ gmail.comwrote in message

news:11 ********************* @ k35g2000prh .googlegro ups.com ...
"rafalK" <kr*******@gmail.comwrote in message
news:11*********************@k35g2000prh.googlegro ups.com...

大家好,

我的STAThread属性存在很大问题。我正在使用XNA框架

与WinForms连接。 XNA正在使用非STAThread。我有一个显示CommonDialog表单的

问题,例如打开文件对话框。因为XNA框架,我不能将主方法声明为STAThread。是

有没有办法在表单中声明表单或某些方法作为STAThread(我认为
认为Form中的方法可以调用OpenFileDialog)也许我是

错了。


你知道我怎么解决问题吗?


谢谢。

RK。
Hi All,
I have a big problem with STAThread attribute. I''m using XNA framework
connected with WinForms. XNA is working in non STAThread. I have a
problem with displaying CommonDialog forms e.g. OpenFileDialog. I
can''t declare a main method as STAThread because of XNA framework. Is
there any way to declare form or some method in form as STAThread (I
think that a method from Form can invoke OpenFileDialog) maybe I''m
wrong.

Do you know how I can resolve a problem?

Thanks.
RK.



Windows窗体应用程序必须使用STAThread属性进行标记,没有

方式。

不确定你的意思是XNA在非STA线程中工作但是,你需要在一个单独的线程中运行XNA代码,或者你在主线程上运行

XNA代码吗?

在后一种情况下,您只需要将STAThread添加到您的主条目中,

第一种情况是您必须通过
$ b $将调用委托给表单b Control.Invoke / BeginInvoke,只要你需要访问From或其中一个元素。

Willy。

A Windows Forms application MUST be tagged with the STAThread attribute, no
way around this.
Not sure what you mean with "XNA is working in non STA Thread" though, do
you mean you are running XNA code in a separate thread, or are you running
XNA code on the main thread?
In the latter case, you simply need to add STAThread to your main entry, in
the first case you''ll have to delegate the calls to the form by means of
Control.Invoke/BeginInvoke whenever you need to access the From or one of
it''s elements.
Willy.


Willy Denoyette [MVP]< wi ************* @ telenet.bewrote:


< snip> ;
Willy Denoyette [MVP] <wi*************@telenet.bewrote:

<snip>

Windows窗体应用程序必须使用STAThread

属性进行标记,无法解决此问题。
A Windows Forms application MUST be tagged with the STAThread
attribute, no way around this.



出于兴趣,如果没有这个问题会有什么问题?对于

测试目的,我经常创建的表单非常少,并且很少

打扰将STAThread属性放在它们上面。他们一直很好 -

但是我很明白,无论是通过偶然还是因为我没有使用特定的组件。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复该群组,请不要给我发邮件

Out of interest, what are the problems one might find without this? For
test purposes I''ve often created forms which do very little, and rarely
bothered to put the STAThread attribute on them. They''ve been fine -
but I quite understand that either this was through chance or because I
wasn''t using particular components.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


我需要的唯一时间是:

*使用Clipboard对象

*使用ActiveX控件/组件


除此之外,我还没有看到任何问题。

省略这个......


Marc
The only times I''ve needed it are when:
* using the Clipboard object
* using ActiveX controls / components

Other than that, I have never seen any issues in the wild when
omitting this...

Marc


这篇关于STAThread与非STAThread框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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