-
September 8th, 2009, 10:28 PM
#1
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.
-
September 9th, 2009, 02:47 AM
#2
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.
-
September 9th, 2009, 03:09 AM
#3
Re: Is Cross Thread exception related to STA/MTA
Originally Posted by sum_gupt
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
-
September 9th, 2009, 11:29 PM
#4
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?
-
September 10th, 2009, 12:12 AM
#5
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.
-
September 10th, 2009, 12:26 AM
#6
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.....
-
September 10th, 2009, 07:23 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|