HELP: how to find list of AppDomain under main process appdomain

  • Thread starter Thread starter Hank
  • Start date Start date
H

Hank

Hi,
I have client and server.
First client calls server, server uses the factory pattern to create a new
domain "newDomain" and object from the domain "newObject".
At certain point, after using the newObject, client need to call server to
dispose the newObject and unload the newDomain.
I tried to unload the newDomain in the newObject.Dispose method, got an
exception. In general, people unload AppDomain from another appdomain. So
I tried a different way. Before client calls the newObject.Dispose method,
it first calls the newObject.GetDomainId() as following:
Client:
......
int domainId = newObject.GetDomainId();
newObject.Dispose(); //Dispose won't call
AppDomain.Unload(CurrentDomain), no exeception thrown
serverFactory.UnloadDomain(domainId); //client calls the main process
domain to unload domain with domainId
......

Server:
class ServerFactory //in the server main process domain
{
void UnloadDomain(int domainId)
{
//HOW do I find the appdomain with domainId, so I can call
AppDomain.Unload( AppDomain ad)
}
}

So I am stuck in the server side, how the server find the domain with
domainId, in other words, more generally is there any method server can call
to get the list of appdomains?

Your help is highly appreciated!
Hang
 
Hi

From the Document, it seems that the Unload method need the AppDomain
reference.
[C#]
public static void Unload(
AppDomain domain
);

So I suggest you hold a HashTable in Serverside to map the
newObject/AppDomain relationship.
e.g. you can hold Object ID in the new Object, and then you want to unload
domain, you can first get the Object ID(the newObject is going to be
disposed), and the use the HashTable to retrieve the AppDomain's
reference, so that we can unload the new AppDomain from the Server's
Default Appdomain.



Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top