AppDomain Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Represents an application domain, which is an isolated environment where applications execute. This class cannot be inherited.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public sealed class AppDomain : MarshalByRefObject

The AppDomain type exposes the following members.

  NameDescription
Public propertyStatic memberCurrentDomainGets the current application domain for the current Thread.
Public propertyFriendlyNameGets the friendly name of this application domain.
Top

  NameDescription
Public methodStatic memberCreateDomainCreates a new application domain with the specified name.
Public methodCreateInstanceAndUnwrapCreates a new instance of the specified type. Parameters specify the assembly where the type is defined, and the name of the type.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public methodGetAssembliesGets the assemblies that have been loaded into the execution context of this application domain.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodLoadLoads an Assembly given its display name.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodStatic memberUnloadUnloads the specified application domain.
Top

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 CreateDomain method. AppDomain instances are used to load and execute assemblies (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.

This class implements the MarshalByRefObject, _AppDomain, and IEvidenceFactory interfaces.

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 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.

Caution noteCaution

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.

TopicLocation
How to: Configure an Application Domain.NET Framework: Programming Fundamentals
How to: Load Assemblies into an Application Domain.NET Framework: Programming Fundamentals
How to: Create an Application Domain.NET Framework: Programming Fundamentals
How to: Unload an Application Domain.NET Framework: Programming Fundamentals
How to: Configure an Application Domain.NET Framework: Programming Fundamentals
How to: Load Assemblies into an Application Domain.NET Framework: Programming Fundamentals
How to: Create an Application Domain.NET Framework: Programming Fundamentals
How to: Unload an Application Domain.NET Framework: Programming Fundamentals
How to: Configure an Application Domain

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: