问题
I have a service app that creates AppDomain's during the course of its use for long running tasks. I've been tracking these by storing them in a Hashtable with a unique ID.
After a task is completed the service app then unloads the AppDomain allocated to that task and then it's removed it from the appdomain Hashtable.
Purely from a sanity checking point of view, is there a way I can query the CLR to see what app domains are still loaded by the creating app domain (i.e. so I can compare the tracking Hashtable against what the CLR actually sees)?
回答1:
AFAIK, you need to keep your own list - like you are already.
回答2:
If you use the unmanaged APIs you may set-up a DomainManager that gets called on each AppDomain creation, and you'll find that many pieces are creating their own AppDomains, e.g. WCF. A detailed explanatin is in Customizing the Microsoft .NET Framework Common Language Runtime
Another route is using the debug APIs.
回答3:
I think you would like to check also this article - "Working with Application Domains in WPF".
来源:https://stackoverflow.com/questions/171541/how-do-i-obtain-a-list-of-the-application-domains-my-application-has-created