Paracom_Inc
asked on
Enumerating the threads in an AppDomain
Is there a way to enumerate the running threads in an AppDomain? I am trying to unload an AppDomain and getting the CannotUnloadAppDomainExcep tion. The docs say that there are three possible causes for this. I'm not trying to unload the default AppDomain. The AppDomain I'm trying to unload is not already unloaded. So, there must be a running thread in the AppDomain that cannot immediately stop execution. I'm trying to find this. Thanks.
ASKER
Sure, that would be great. Can you suggest how I might do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
"Multiple application domains can run in a single process; however, there is not a one-to-one correlation between application domains and threads. Several threads can belong to a single application domain, and while a given thread is not confined to a single application domain, at any given time, a thread executes in a single application domain." Threads are free to cross application domain boundaries as the Win32 thread scheduler and CLR see fit. Also the unmanaged threads are another issue you can't control.
You can find out the OS threads related to your process but those are not equal to managed threads. Also you don't have the possibility to kill them (they are ProcessThread not Thread). Therefore I don't think your problem can be solved this way. Wouldn't be better to find out which is the thread that doesn't stop - if that's the real reason?