Question

I have recently started studying about threads. I thought of starting from the beginning and started reading MSDN documentation. Read about ApplicationDomain which is separate for each application. But in this link ApplicationDomain and Threads it is mentioned that

Several threads can be executing in a single application domain at any given time and a particular thread is not confined to a single application domain. That is, threads are free to cross application domain boundaries

If a user created a thread and if it is allowed to cross application domain, then can it refer to the objects or memory reference of another applicationdomain ??? Please guide me if I am wrong.

Was it helpful?

Solution

There is no one-one relationship between application domains and threads. Although a thread may cross an application domain boundary, at any one time, the thread is executing in a single application domain.

See the below information from MSDN (http://msdn.microsoft.com/en-us/library/2bh4z9hs%28v=vs.90%29.aspx):

Code running in one application cannot directly access code or resources from another application. The common language runtime enforces this isolation by preventing direct calls between objects in different application domains. Objects that pass between domains are either copied or accessed by proxy. If the object is copied, the call to the object is local. That is, both the caller and the object being referenced are in the same application domain. If the object is accessed through a proxy, the call to the object is remote. In this case, the caller and the object being referenced are in different application domains. Cross-domain calls use the same remote call infrastructure as calls between two processes or between two machines.

Also the following article may be useful: http://www.codeproject.com/Articles/26148/Beginners-Guide-to-Threading-in-NET-Part-1-of-n

OTHER TIPS

The answer is yes. Every thread has a stack which can point to arbitrary object. The local variable on the threads stack are GC roots, meaning they will keep everything alive as long as the thread is alive.

A thread runs code, it can not refer to an application specific types or objects.

Most of the properties of a thread are read only, and the ones you will are very specific (like CurrentCultre) cannot be used to pass custom types.

The only way to associate data with a specific thread is by using Thread Local Storage which of course will not pass from Application Domain to another and is only useful in very specific cases.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top