How to unload AppDomain created by CreateApplicationHost()?

G

Guest

Hi,

I noticed that releasing the reference ot the returned by
CreateApplicationHost() is not enough to free memory taken by AppDomain
created by CreateApplicationHost(). I have to created and destroy ASP.NET
AppDomains on a fly without terminating the proccess. I want to get a
reference to the AppDomain object created by CreateApplicationHost() so I
could call AppDomain.Uload(), but can't find any information about it.

Will appreciate a snippet illustrating how to get a hold of the new
AppDomain from the thread that called CreateApplicationHost().

Thank you,
 
G

Guest

Never mind, I've figured it out.

Since CreateApplicationHost() creates a host object in the new domain, it's
enough to just create a method in the host class that returns current
AppDomain. It should look like this:
public AppDomain GetAppDomain()
{
return Thread.GetDomain();
}

Once ASP.NET domain is not needed anymore, it's possible to call
AppDomain.Unload(_host.GetAppDomain());

Weird things is that none of the examples showing how to use
CreateApplicationHost() mentions how to force ASP.NET appdomain unloading,
even if the domain will get unloaded eventually on its own after the
application is unloaded.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,052
Members
48,769
Latest member
Clifft

Latest Threads

Top