每个人都需要知识!! [英] need knowledge, everyone!!

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

问题描述

大家好,

我只是C#的新手.我看到了很多程序,但是大多数程序对我来说都很令人困惑..你能帮我吗?

在主Program.cs中,
我不知道一件事.

hi everyone,

i am just a new in C#. i saw many programs but most of the programs are confusing for me..could u help me?

in main Program.cs,
there is one thing i don''t know..

static class Program
   {
       [STAThread]
       static void Main()
       {

       }



在此示例中,这是什么意思[] ??
我用[]看了很​​多程序.



in this example, what does it mean [] ??
i saw many programs with [ ].
what does it suppose to mean??

推荐答案

STAThreadAttribute本质上是Windows消息泵与COM组件进行通信的要求.尽管核心Windows窗体不使用COM,但操作系统的许多组件(例如系统对话框)仍使用此技术.

MSDN更详细地解释了原因:

STAThreadAttribute指示应用程序的COM线程模型是单线程单元.在使用Windows窗体的任何应用程序的入口点上都必须存在此属性.如果省略,则Windows组件可能无法正常工作.如果该属性不存在,则应用程序将使用Windows窗体不支持的多线程单元模型.

这篇博客文章(为什么需要STAThread?)也很好地解释了这一要求.如果您想更深入地了解线程模型在CLR级别的工作方式,请参阅此MSDN杂志文章.
看看这篇文章:
http://msdn.microsoft.com/en-us/library/system.stathreadattribute.aspx [^ ]
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 explains the reason in slightly more detail:

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.

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.
have a look at this article:
http://msdn.microsoft.com/en-us/library/system.stathreadattribute.aspx[^]


亲爱的朋友,

[]表示ATTRIBUTE.

STAThread属性与COM组件有关,或多或少与您的应用程序具有多少个线程无关.

因此,应用程序可以是STAThread''ede(单线程单元),并且仍然具有多个线程.

Dear friend,

[] means ATTRIBUTE.

The STAThread attribute is related to COM components, and has more or less nothing to do with how many threads you application has.

So, an application can be STAThread''ede (Single-Threaded Apartment) and still have multiple threads.

759,000 results what is stathread in c#?

I hope this will clear your confusion. Please don''t forget to mark this as your answer if it helps you out.

Thanks


这些是属性.
您可以在c#
中搜索有关属性的各种文章
^ ]
^ ]
^ ]
These are attributes.
you can search for various articles on attributes in c#
Attributes in C#[^]
http://msdn.microsoft.com/en-us/library/aa288454(v=vs.71).aspx[^]
http://msdn.microsoft.com/en-us/library/byxd99hx(v=vs.71).aspx[^]


这篇关于每个人都需要知识!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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