是什么[STAThread]吗? [英] What does [STAThread] do?

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

问题描述

我学习C#3.5,我想知道是什么 [STAThread] 确实在我们的计划?

I am learning C# 3.5 and I want to know what [STAThread] does in our programs?

推荐答案

请将STAThreadAttribute 基本上是一个为Windows消息泵与COM组件进行通信的要求。尽管核心的Windows窗体不使用COM,如系统对话框操作系统的许多组件做使用该技术。

The STAThreadAttribute is essentially a requirement for the Windows message pump to communicate with COM components. Although core Windows Forms does not use COM, many components of the OS such as system dialogs do use this technology.

MSDN 解释稍微详细的原因:

MSDN explains the reason in slightly more detail:

请将STAThreadAttribute表明
  为COM线程模型
  应用程序是单线程
  公寓。此属性必须是
  对任何一个入口点present
  应用程序,使用Windows窗体;
  如果它被省略,在Windows
  组件可能无法正常工作。
  如果属性不是present中,
  应用程序使用多线程
  公寓的模式,这是不
  支持Windows窗体。

STAThreadAttribute indicates that the COM threading model for the application is single-threaded apartment. This attribute must be present on the entry point of any application that uses Windows Forms; if it is omitted, the Windows components might not work correctly. If the attribute is not present, the application uses the multithreaded apartment model, which is not supported for Windows Forms.

本博客文章为什么STAThread需要?的),也说明需求相当不错。如果你想有一个更深入的视图的线程模型的工作原理在CLR级别,请参见这个MSDN杂志文章

This blog post (Why is STAThread required?) also explains the requirement quite well. If you want a more in-depth view as to how the threading model works at the CLR level, see this MSDN Magazine article.

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

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