public sealed class AppDomain : MarshalByRefObject
Object
MarshalByRefObject
AppDomain
mscorlib
RuntimeInfrastructure
Represents an application domain, which is an isolated environment where applications execute.
Application domains, which are represented by AppDomain objects, provide isolation, unloading, and security boundaries for executing managed code.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 a AppDomain is no longer in use, it can be unloaded.The AppDomain class implements a set of events to enable applications to respond to the following conditions:
Condition Event An assembly was loaded.
System.AppDomain.AssemblyLoad An application domain will be unloaded. System.AppDomain.DomainUnload An unhandled exception was thrown. System.AppDomain.UnhandledException
System Namespace
AppDomain Methods
AppDomain.CreateDomain Method
AppDomain.ToString Method
AppDomain.Unload Method
AppDomain Properties
AppDomain.FriendlyName Property
AppDomain Events
AppDomain.AssemblyLoad Event
AppDomain.DomainUnload Event
AppDomain.UnhandledException Event
public static AppDomain CreateDomain(string friendlyName);
Creates and returns a new application domain with the specified name.
- friendlyName
- A String containing the friendly name of the domain.
A AppDomain representing the newly created application domain.
Exception Type Condition ArgumentNullException friendlyName is null
.
[Note: The friendlyName parameter is intended to identify the domain in a manner that is meaningful to humans. This string should be suitable for display in user interfaces. ]
System.AppDomain Class, System Namespace
public override string ToString();
Returns a String representation of the current instance.
A String containing information about the current AppDomain instance.
The string returned by this method includes the friendly name of the application domain.[Note: This method overrides System.Object.ToString .]
System.AppDomain Class, System Namespace
public static void Unload(AppDomain domain);
Unloads the specified application domain.
- domain
- A AppDomain representing the application domain to be unloaded.
Exception Type Condition ArgumentNullException domain is null
.CannotUnloadAppDomainException domain could not be unloaded.
If the thread that invoked System.AppDomain.Unload(System.AppDomain) is running in domain, another thread is started to perform the unload operation. If domain cannot be unloaded, a CannotUnloadAppDomainException is thrown in that thread, not the original thread that invoked System.AppDomain.Unload(System.AppDomain). However, if the thread that invoked System.AppDomain.Unload(System.AppDomain) is running outside domain, that is the thread that receives the exception.The threads in domain are terminated using the System.Threading.Thread.Abort(System.Object) method, which throws the thread an instance of ThreadAbortException. [Note: Although the thread should terminate promptly, it can continue executing for an unbounded amount of time in its
finally
clause.]
System.AppDomain Class, System Namespace
public string FriendlyName { get; }
Gets the friendly name of the current instance.
A String containing the friendly name of the current application domain.
This property is read-only.The friendly name of a AppDomain instance created by an application is specified to the constructor. The friendly name of the default AppDomain is the name of the assembly file loaded in the application domain. The friendly name is formed by stripping the directory information from the assembly's file name. For example, if the loaded assembly has the name
"\MyAppDirectory\MyAssembly.exe"
, the friendly name of the default application domain is"MyAssembly.exe"
.
System.AppDomain Class, System Namespace
public event AssemblyLoadEventHandler AssemblyLoad
Raised when an assembly is loaded.
[Note: This event is handled by a AssemblyLoadEventHandler delegate. Information about the event is passed to the delegate in a AssemblyLoadEventArgs instance.For additional information about events, see Partitions I and II of the CLI Specification.
]
System.AppDomain Class, System Namespace
public event EventHandler DomainUnload
Raised when a AppDomain is about to be unloaded.
[Note: This event is handled by a EventHandler delegate. Information about the event is passed to the delegate in a EventArgs instance. The delegate for this event can perform any termination activities before the application domain is unloaded.For additional information about events, see Partitions I and II of the CLI Specification.
]
System.AppDomain Class, System Namespace
public event UnhandledExceptionEventHandler UnhandledException
Raised when an exception is not caught by the default application domain.
[Note: This event is handled by a UnhandledExceptionEventHandler delegate. Information about the event is passed to the delegate in a UnhandledExceptionEventArgs instance. The delegate provides default handling for uncaught exceptions. When this event is not handled, the system default handler reports the exception to the user and might terminate the application. For additional information, see System.UnhandledExceptionEventArgs.IsTerminating. ]
This event is raised only for the application domain that is created by the system when an application is started. If an application creates additional application domains, specifying a delegate for this event in those applications domains has no effect.
[Note: For additional information about events, see Partitions I and II of the CLI Specification.]
System.AppDomain Class, System Namespace