none
Reg STA Components behavior in C# RRS feed

  • Question

  • Hi Everybody,

    I am facing one interoperability issue in C#.

    Our project is a set of unmanaged ATL/COM components written in VC++.

    These are created with STA attributes.When we are trying to create
    object for the components in C# application with STAThread attribute
    in the main,It is working fine.

    If I change the attribute to MTAThread, it is giving an exception.

    My question is,

    1. Can I load my STA Components in my C# [.NET] application with
    MTAThread attribute?.
    2. If so, will the behaviour be same as it is for when we load it with
    STAThread attribute?.
    3. If the behaviour differs how can we make it to behave similarly in
    both STAThread and MTAThread atributes?.

    Advanced thanks for your support and help.

    regards
    Vairavan
    Sunday, February 10, 2008 5:06 PM

Answers

  • Can I load my STA Components in my C# [.NET] application with MTAThread attribute?.

    No, An object(the marked as STA component in this case) that needs synchronization (because its methods use thread sensitive data) but does not provide it itself must run in a single-threaded apartment (STA), which guarantees that only a single thread will access the object regardless of the thread that initialized the call.
    Monday, February 11, 2008 5:53 AM

All replies

  • Can I load my STA Components in my C# [.NET] application with MTAThread attribute?.

    No, An object(the marked as STA component in this case) that needs synchronization (because its methods use thread sensitive data) but does not provide it itself must run in a single-threaded apartment (STA), which guarantees that only a single thread will access the object regardless of the thread that initialized the call.
    Monday, February 11, 2008 5:53 AM
  • Thanks Verymuch for your reply.Can I change my Components thread attribute to "Both" and load it in my C# application with "MTAThread" Attribute?.

     

    If you can help in this regard I will be really thankfull to you.

     

    regards

    Vairavan

    Sunday, February 17, 2008 8:34 AM
  • You can set the Threading Model Attribute of your component. For more details, please visit What are these "Threading Models" and why do I care?
    Wednesday, February 20, 2008 10:49 AM