ApplicationDomain.Unload Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Unloads the application domain.
public:
void Unload();
public void Unload ();
member this.Unload : unit -> unit
Public Sub Unload ()
Examples
The following example demonstrates how to view all properties and unload an application domain.
using System;
using Microsoft.Web.Administration;
namespace AdministrationSnippets
{
public class MicrosoftWebAdministrationApplicationDomain
{
ServerManager manager = new ServerManager();
public void RecycleApplicationDomains()
{
Console.WriteLine("Displaying Worker Processes & Application Domains...");
GetApplicationDomains();
Console.WriteLine("Unloading all application domains");
UnloadApplicationDomains();
Console.WriteLine("Displaying Worker Processes & Application Domains with new IDs...");
GetApplicationDomains();
}
public void UnloadApplicationDomains()
{
foreach (WorkerProcess proc in manager.WorkerProcesses)
{
foreach (ApplicationDomain ad in proc.ApplicationDomains)
{
ad.Unload();
}
}
}
public void GetApplicationDomains()
{
foreach (WorkerProcess proc in manager.WorkerProcesses)
{
Console.WriteLine("Worker Process Found:");
Console.WriteLine("\tProcessId: {0}", proc.ProcessId);
Console.WriteLine("\tProcessGuid: {0}", proc.ProcessGuid);
Console.WriteLine("\tAppPoolName: {0}", proc.AppPoolName);
Console.WriteLine("\tApplication Domains:");
foreach (ApplicationDomain ad in proc.ApplicationDomains)
{
Console.WriteLine("\t\tApplication Domain Found:");
Console.WriteLine("\t\t{0}", ad.Id );
Console.WriteLine("\t\t{0}", ad.VirtualPath );
Console.WriteLine("\t\t{0}", ad.PhysicalPath );
Console.WriteLine("\t\t{0}", ad.Idle);
}
}
}
}
}
Remarks
This method unloads the application domain and releases references to any assemblies the application domain has loaded.
The unload operation is not complete until the application domain's threads have been terminated.
The Unload method terminates the threads in the application domain by calling the System.Threading.Thread.Abort method on each thread. Although the threads should terminate promptly, they can continue to execute for an unpredictable period of time.