Share via


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.

Inheritance Hierarchy

System. . :: . .Object
  System. . :: . .MarshalByRefObject
    System..::..AppDomain

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

Syntax

'Declaration
Public NotInheritable Class AppDomain _
    Inherits MarshalByRefObject
public sealed class AppDomain : MarshalByRefObject
public ref class AppDomain sealed : public MarshalByRefObject
[<Sealed>]
type AppDomain =  
    class
        inherit MarshalByRefObject
    end
public final class AppDomain extends MarshalByRefObject

The AppDomain type exposes the following members.

Properties

  Name Description
Public propertyStatic member CurrentDomain Gets the current application domain for the current Thread.
Public property FriendlyName Gets the friendly name of this application domain.

Top

Methods

  Name Description
Public methodStatic member CreateDomain Creates a new application domain with the specified name.
Public method CreateInstanceAndUnwrap Creates a new instance of the specified type. Parameters specify the assembly where the type is defined, and the name of the type.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public method GetAssemblies Gets the assemblies that have been loaded into the execution context of this application domain.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Load Loads an Assembly given its display name.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public methodStatic member Unload Unloads the specified application domain.

Top

Remarks

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.

Warning

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.

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

Thread Safety

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

See Also

Reference

System Namespace