CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2006
    Posts
    8

    Exclamation Is Cross Thread exception related to STA/MTA

    Hello All,
    Can anybody provide the description about Single Threaded Apartment(STA) and MultiThreaded aprtment(MTA)??? I have already read several posts on these, but I am not getting the clear concept of these.

    And please also describe that... is there any relation b/w cross thread exception and STA/MTA.
    (The exception that gets raised when control is accessed by the thread other than thread that created the control).

    Thanks in advance to all of you.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,185

    Re: Is Cross Thread exception related to STA/MTA

    The STA / MTA is to determine the threading model your application uses. This has nothing to do with cross thread operations.

    The reason you are having cross thread operations is because you are setting a UI element property from a non-UI thread.

    For example, you start your application (by default 1 thread, the UI one). Then, to speed up things or to perform a long-time operation, you start a background thread. In the background thread, you directly set a property of the UI.

    This is not allowed, since UI elements may be accessed only from the thread that created the UI (the first one). You will need to invoke the call to the UI from the right thread so the UI can be accessed.

  3. #3
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Is Cross Thread exception related to STA/MTA

    Quote Originally Posted by sum_gupt View Post
    Hello All,
    Can anybody provide the description about Single Threaded Apartment(STA) and MultiThreaded aprtment(MTA)??? I have already read several posts on these, but I am not getting the clear concept of these.
    The answer to these kind of questions can almost always be found on MSDN. I would recommend to you to use this in future.

    Here the descriptions
    STA
    MTA

  4. #4
    Join Date
    Mar 2006
    Posts
    8

    Re: Is Cross Thread exception related to STA/MTA

    Hello Tischnoetentoet,
    What I exactly want to know is" What is the reason that cross thread operations are not allowed"? can u plz explain the root cause of the problem?

  5. #5
    Join Date
    Nov 2003
    Posts
    2,185

    Re: Is Cross Thread exception related to STA/MTA

    The root of the problem is that UI elements may only be touched by one thread, and that is the thread that created the UI element.

  6. #6
    Join Date
    Mar 2006
    Posts
    8

    Re: Is Cross Thread exception related to STA/MTA

    Hello Tischnoetentoet,
    I agree from you, but what you are telling is not the root cause.
    I m looking for something: for e.g.
    The UI thread runs in one container,
    the other threads run in other containers,
    So directly outside threads do not access the
    UI thread objects, that have to redirect the call
    through Contro.Invoke()....

    but I want some more descriptive.....

  7. #7
    Join Date
    Nov 2003
    Posts
    2,185

    Re: Is Cross Thread exception related to STA/MTA


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured