Permalink
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (33 sloc) 2.42 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
How to: Unload an Application Domain
03/30/2017
.net-framework
dotnet-bcl
article
Unload method
application domains, unloading
unloading application domains
f356116d-e415-4f7c-a332-6e6a60227192
10
rpetrusha
ronpet
wpickett

How to: Unload an Application Domain

When you have finished using an application domain, unload it using the xref:System.AppDomain.Unload%2A?displayProperty=nameWithType method. The Unload method gracefully shuts down the specified application domain. During the unloading process, no new threads can access the application domain, and all application domain–specific data structures are freed.

Assemblies loaded into the application domain are removed and are no longer available. If an assembly in the application domain is domain-neutral, data for the assembly remains in memory until the entire process is shut down. There is no mechanism to unload a domain-neutral assembly other than shutting down the entire process. There are situations where the request to unload an application domain does not work and results in a xref:System.CannotUnloadAppDomainException.

The following example creates a new application domain called MyDomain, prints some information to the console, and then unloads the application domain. Note that the code then attempts to print the friendly name of the unloaded application domain to the console. This action generates an exception that is handled by the try/catch statements at the end of the program.

Example

[!code-cppSystem.AppDomain.Load#3] [!code-csharpSystem.AppDomain.Load#3] [!code-vbSystem.AppDomain.Load#3]

See Also

Programming with Application Domains
How to: Create an Application Domain
Using Application Domains