[STAThread]
是Single  Thread  Apartment单线程套间的意思 
是一种线程模型。其它的好像还是MTA(多线程套间)、Free  Thread(自由线程)  
这个属性要加在主  Main  上。这个属性只在  Com  Interop  所用,如果全部是  managed  code  则无用。 []是用来表示Attributes 。

解决方案 »

  1.   

    在C#中自己写的组件(Component)和控件(UserControl),加到工具箱上时,图标总是一个黄色的齿轮图标。ToolboxBitmap属性就是把自己写的组件和控件换成自己的图标,以便于分辨.
    [ToolboxBitmap("open.bmp")]//注意:参数为你的位图路径
    public class Test:System.Windows.Forms.UserControl  //控件
    {
    省略
    }
    }
      

  2.   

    [DefaultProperty(  "Text  ")]
    设定了该控件的默认属性。当你把该控件拖到Form上时,在属性框中该属性就是当前项。比如TextBox
     
    还有如:
    [DefaultEvent(  "Click  ")]设定了该控件的默认事件。当你在属性框中选择  "Events  "按钮切换到事件框时,默认的事件会自动被选中,或者当你双击该控件时,IDE会自动为你添加的那个事件处理函数。比如:  Button
      

  3.   

    [DllImport("User32.dll")]
    倒入win32动态链接库
      

  4.   

    from <<inside C#>> 有点像aop 好玩using System;
    using System.Runtime.Remoting.Contexts;
    using System.Threading;// for IMessageSink 
    using System.Runtime.Remoting.Messaging;// for IConstructionCallMessage
    using System.Runtime.Remoting.Activation;namespace ContextAttribs
    {
        public class FooObjectSink : IMessageSink
        {
            private IMessageSink next;
            public FooObjectSink (IMessageSink ims) { next = ims; }
            public IMessage SyncProcessMessage (IMessage imCall)
            {
                Console.WriteLine("\nPreprocessing...");
                IMessage imReturn = next.SyncProcessMessage(imCall);
                Console.WriteLine("...Postprocessing\n");
                return imReturn;
            }
            public IMessageCtrl AsyncProcessMessage (
                IMessage imCall, IMessageSink ims) { return null; }
            public IMessageSink NextSink { get { return next; } }
        }    public class FooProperty : 
            IContextProperty, IContributeObjectSink
        {
            public IMessageSink GetObjectSink(
                MarshalByRefObject o, IMessageSink next)
            {
                return new FooObjectSink(next);
            }
            public bool IsNewContextOK(Context c) { return true; }
            public void Freeze(Context c) { return; }
            public string Name { get { return "Foo"; } }
        }    [AttributeUsage(AttributeTargets.All)]
        public class FooAttribute : ContextAttribute
        {
            public FooAttribute() : base("Foo") 
            {
                Console.WriteLine("FooAttribute instance ctor");
            }
            static FooAttribute()
            {
                count = 1;
                Console.WriteLine("FooAttribute static ctor");
            }
            public static int Count
            {
                get { return count++; }
            }
            private static int count;        public override bool IsContextOK(Context c, 
                IConstructionCallMessage ctor)
            {
                return false;
            }
            public override void GetPropertiesForNewContext(
                IConstructionCallMessage ctor)
            {
                ctor.ContextProperties.Add(new FooProperty());
            }
        }    [Foo]
        public class SomeClass : ContextBoundObject
        {
            public string name;
            public SomeClass(string s)
            {
                name = s;
                Console.WriteLine("{0} created", name);
            }
            public void SomeFunc()
            {
                Console.WriteLine("{0}, SomeFunc: {1}", 
                    name, FooAttribute.Count);
            }
        }    class Test1
        {
            [STAThread]
            static void Main(string[] args)
            {
                SomeClass sc = new SomeClass("Bill");
                sc.SomeFunc();            SomeClass sc2 = new SomeClass("Mary");
                sc2.SomeFunc();            sc.SomeFunc();
            }
        }
    }
    This is the run-time output:FooAttribute static ctor
    FooAttribute instance ctor
    Bill createdPreprocessing...
    Bill, SomeFunc: 1
    ...PostprocessingFooAttribute instance ctor
    Mary createdPreprocessing...
    Mary, SomeFunc: 2
    ...PostprocessingPreprocessing...
    Bill, SomeFunc: 3
    ...Postprocessing
      

  5.   

    我仅仅知道它是属性
    但是为什么要有两个属性了

    public string {get;set}
    [STAThread]
    这也是属性,有什么区别呢?
    求教