Represents an application domain, which is an isolated environment where applications execute. This class cannot be inherited.
See Also: AppDomain Members
Application domains, which are represented by AppDomain objects, help provide isolation, unloading, and security boundaries for executing managed code.
Use application domains to isolate tasks that might bring down a process. If the state of the AppDomain that's executing a task becomes unstable, the AppDomain can be unloaded without affecting the process. This is important when a process must run for long periods without restarting. You can also use application domains to isolate tasks that should not share data.
If an assembly is loaded into the default application domain, it cannot be unloaded from memory while the process is running. However, if you open a second application domain to load and execute the assembly, the assembly is unloaded when that application domain is unloaded. Use this technique to minimize the working set of long-running processes that occasionally use large DLLs.
Multiple application domains can run in a single process; however, there is not a one-to-one correlation between application domains and threads. Several threads can belong to a single application domain, and while a given thread is not confined to a single application domain, at any given time, a thread executes in a single application domain.
Application domains are created using the AppDomain.CreateDomain(string, System.Security.Policy.Evidence) method. AppDomain instances are used to load and execute assemblies (System.Reflection.Assembly). When an AppDomain is no longer in use, it can be unloaded.
The AppDomain class implements a set of events that enable applications to respond when an assembly is loaded, when an application domain will be unloaded, or when an unhandled exception is thrown.
For more information on using application domains, see Application Domains.
You should never create a remotable wrapper for an AppDomain object. Doing so could publish a remote reference to that AppDomain, exposing methods such as erload:System.AppDomain.CreateInstance to remote access and effectively destroying code access security for that AppDomain. Malicious clients connecting to the remoted AppDomain could obtain access to any resource the AppDomain itself has access to. Do not create remotable wrappers for any type that extends MarshalByRefObject and that implements methods that could be used by malicious clients to bypass the security system.
The default value for the AppDomainSetup.DisallowCodeDownload property is false. This setting is unsafe for services. To prevent services from downloading partially trusted code, set this property to true.