none
stathread, mtathread

    Question

  • What is STAThread, MTAThread... I remember .NET CF didnot support MTAThread... why main() is decorated with them...
    - Rajesh K http://thoughtsontechies.blogspot.com/
    Thursday, April 7, 2011 10:15 AM

Answers

  • They stand for "Single Threaded Apartment" and "Multi Threaded Apartment" and are used to control threading mechanisms for COM interop. You would typically decorate your entry point method using one of them to tell the runtime to set the threading apartment for the main thread (GUI thread in Win Forms).

    There are some parts of the .NET framework that requires STA, such as the Clipboard (that uses COM under the hood), so any Win Forms application should normally use the STAThread attribute.
    This has no impact on managed threads and an application can be "multithreaded" regardless of what threading apartment is used.

    There are lots of information on the subject out there, but unless you're working heavily with COM from your .NET application this is really all you need to know.

    /Calle


    - Still confused, but on a higher level -
    • Marked as answer by Paul Zhou Monday, April 18, 2011 2:47 AM
    Thursday, April 7, 2011 1:38 PM

All replies

  • They stand for "Single Threaded Apartment" and "Multi Threaded Apartment" and are used to control threading mechanisms for COM interop. You would typically decorate your entry point method using one of them to tell the runtime to set the threading apartment for the main thread (GUI thread in Win Forms).

    There are some parts of the .NET framework that requires STA, such as the Clipboard (that uses COM under the hood), so any Win Forms application should normally use the STAThread attribute.
    This has no impact on managed threads and an application can be "multithreaded" regardless of what threading apartment is used.

    There are lots of information on the subject out there, but unless you're working heavily with COM from your .NET application this is really all you need to know.

    /Calle


    - Still confused, but on a higher level -
    • Marked as answer by Paul Zhou Monday, April 18, 2011 2:47 AM
    Thursday, April 7, 2011 1:38 PM
  •  

    Hi Rajesh,

     

    Has your issue been resolved? Would you mind letting us know the result of the suggestions?

     

    Now I will mark an answer, you can mark others that you think to be so useful to your issue.

    You could “Unmark As Answer” if it doesn’t make sense.

     

    Have a nice day!


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 18, 2011 2:47 AM