>
About threads crossing application domains, you need to make a clear
distinction between hard threads (OS threads) and soft threads (CLR threads) here.
While hard threads don't have application domain affinity (they are not
tied to a specific application domain), CLR threads do have this affinity so they cannot cross AD. borders.
Willy.
The information that I have read indicates that CLR threads are not bounded
to a single appdomain. I agree that there is a distinction between OS
threads and CLR threads. A CLR thread is an object that is mapped to an OS
thread, that the mapping between a CLR thread and an OS thread can change,
and an OS thread can be mapped to different CLR thread objects at different
times. However, this is an implementation detail of the current version of
the CLR and may change in the future (e.g. if the CLR ever implements
threading on top of fibers instead of OS threads). I disagree that CLR
threads are bounded by AD borders.
Here is a direct quote from the documentation of the Thread class:
"GetHashCode provides identification for managed threads. For the lifetime
of your thread, it will not collide with the value from any other thread,
regardless of the application domain from which you obtain the value.
Note An operating-system ThreadId has no fixed relationship to a managed
thread, because an unmanaged host can control the relationship between
managed and unmanaged threads. Specifically, a sophisticated host can use
the CLR Hosting API to schedule many managed threads against the same
operating system thread, or to move a managed thread between different
operating system threads."
This clearly implies that the thread of execution can cross appdomain
boundaries. Now, it may be that the CLR thread object is bounded in the
sense that because it is not derived from MarshalByRefObj a direct reference
to that object cannot be passed to another appdomain (a copy of the object
such that a new copy that preserves the original identity would be used in
the other appdomain). However, this is not the same thing as the current
thread of execution.
These details are of interest to those of us that like to know what is going
on below the surface; managed code almost never needs to know about this.
From the perspective of an application a sequence of instructions is
executed on a logical thread and the logical thread can cross appdomain
boundaries and preserve its CLR identity.
If my understanding of this is incorrect then please provide more
information.
Dave