Name

AppDomain

Synopsis

This class represents an abstract separation within the executing process, which mimics the separation between processes running on a single machine. As a result, a single .NET process can host multiple other processes that offer the isolation found between processes, while keeping the low overhead of a single process.

Every .NET process created has at least one AppDomain, even when running a simple command shell-driven application, such as Hello, world, created by the shim code at the start of a .NET executable file. Applications that act as containers, however, can create multiple AppDomains, loading assemblies into each AppDomain independently of one another. This is, in fact, precisely how ASP.NET keeps multiple web applications separate from one another, so that an exception thrown from within one won’t tear down the entire IIS process.

Creating a new AppDomain involves using the static CreateDomain() method. This method is overloaded four ways, but the most common use is simply to pass in a friendly name for the AppDomain. When finished with a given AppDomain, use the Unload() method to close down the AppDomain and all objects stored within it. Should a .NET programmer wish to obtain a reference to the AppDomain she is currently executing within, the static property CurrentDomain returns the current AppDomain.

Each AppDomain contains an entirely separate list of loaded assemblies accessible via the GetAssemblies() method, which returns the list of ...

Get C# in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.