[STAThread] [英] [STAThread]

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

问题描述

您好,


任何人都可以在Main方法面前向我介绍这个[STAThread]是什么意思

for?

什么时候必须在那里,什么时候可选?


谢谢你。

解决方案

Warren,


这是放在windows应用程序的入口点(和控制台I

思考),表明这个帖子是单个公寓的线程。这是用于COM互操作的
,其中一些控件(例如富文本框)

需要提供它们的功能。把它放在那里并没有什么坏处,

除非你正在做一些会干扰这个的COM互操作。


它没有伤害把它放在那里,通常最好留下它b / b
除非你绝对确定在该线程上没有执行COM互操作

(框架中的一些课程

也要求。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- nick(dot)paldino = at = exisconsulting< dot> com


" ;沃伦" < WA ********* @ yahoo.com>在留言中写道

news:3f ******** @ news.starhub.net.sg ...

你好,
任何人都可以在主要方法面前告诉我这个[STAThread]是什么?
什么时候必须在那里,什么时候可选?

谢谢。



如果你想获得一个关于STAThread的内容,请查看DCOM邮件存档和

其他COM大约1998年的资源..你会发现所有有关STAThreads以及它们如何工作以及为什么需要它以及.NET框架如何实现需要的所有知识




哦,MSDN也有帮助.. :)


-

Girish Bharadwaj

Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com>写在

消息新闻:好的************** @ tk2msftngp13.phx.gbl ...

Warren,
这是放在Windows应用程序的入口点(和我认为的控制台
),以表明此线程是单公寓线程。这个
用于COM互操作,其中一些控件(例如富文本
框)需要提供它们的功能。把它放在那里并没有什么坏处,
除非你正在做一些可以干扰它的COM互操作。

把它放在那里并没有什么坏处,它是通常最好留下
,除非你绝对确定在该线程上没有执行COM互操作(
框架中的某些类也需要) 。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- nick(dot)paldino = at = exisconsulting< dot> com

" warren" < WA ********* @ yahoo.com>在消息中写道
新闻:3f ******** @ news.starhub.net.sg ...

你好,

任何人都可以简报我在Main方法面前的这个[STAThread]是什么?
什么时候必须在那里,什么时候可选?

谢谢。




仅Winforms应用程序需要STAThread。

此属性初始化主线程要在单线程公寓(STA)中运行,Windows应用程序需要这样:

- 拖放支持

- 一些Windows控件(确定它们是COM / ActiveX服务器) )具有线程亲和性,因此应该在STA中创建。


其他应用程序(控制台,服务)通常没有相同的要求,但最好是明确的为MTA初始化主要的

线程。


Willy。


" warren" < WA ********* @ yahoo.com>在留言新闻中写道:3f ******** @ news.starhub.net.sg ...

你好,

任何人都能告诉我这是什么[STAThread]在Main方法面前
for?
什么时候必须在那里,什么时候可选?

谢谢。


Hello,

Anyone can brief me what is this [STAThread] in front of the Main method
for?
and when must it be there, and when is it optional?

thank you.

解决方案

Warren,

This is placed on the entry point of windows applications (and console I
think), to indicate that this thread is a single-apartment thread. This is
used for COM interop, which some of the controls (such as the rich text box)
require to provide their functionality. It doesn''t hurt to have it there,
unless you are doing some COM interop which would interfere with this.

It doesn''t hurt to have it there, and it is generally better to leave it
there, unless you are absolutely sure that there is no COM interop being
executed on that thread as well (which some of the classes in the framework
require as well).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"warren" <wa*********@yahoo.com> wrote in message
news:3f********@news.starhub.net.sg...

Hello,

Anyone can brief me what is this [STAThread] in front of the Main method
for?
and when must it be there, and when is it optional?

thank you.



If you want to get a lowdown on STAThread, look in DCOM mailing archives and
other COM resources circa 1998.. You will find out all there is to know
about STAThreads and how they work and why its needed and how .NET framework
realized the need for this.

Oh, MSDN helps too.. :)

--
Girish Bharadwaj
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Ok**************@tk2msftngp13.phx.gbl...

Warren,

This is placed on the entry point of windows applications (and console I think), to indicate that this thread is a single-apartment thread. This is used for COM interop, which some of the controls (such as the rich text box) require to provide their functionality. It doesn''t hurt to have it there,
unless you are doing some COM interop which would interfere with this.

It doesn''t hurt to have it there, and it is generally better to leave it there, unless you are absolutely sure that there is no COM interop being
executed on that thread as well (which some of the classes in the framework require as well).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"warren" <wa*********@yahoo.com> wrote in message
news:3f********@news.starhub.net.sg...

Hello,

Anyone can brief me what is this [STAThread] in front of the Main method
for?
and when must it be there, and when is it optional?

thank you.




STAThread is only required for Winforms applications.
This attribute initializes the main thread to run in a Single Threaded Apartment (STA), windows applications need this for:
- drag and drop support
- some windows controls (sure they are COM/ActiveX servers) have thread affinity, so should be created in an STA.

Other applications (console, services) normally don''t have the same requirements, but it''s better to explicitly initialize the main
thread for MTA.

Willy.

"warren" <wa*********@yahoo.com> wrote in message news:3f********@news.starhub.net.sg...

Hello,

Anyone can brief me what is this [STAThread] in front of the Main method
for?
and when must it be there, and when is it optional?

thank you.



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

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