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(对于一个长时间运行的process偶尔用一个大的dll,创建新的appdomain,在不用的时候unload掉).
多个应用程序域可以在一个进程中运行;但是,在应用程序域和线程之间没有一对一的关联。多个线程可以属于一个应用程序域,尽管给定的线程并不局限于一个应用程序域,但在任何给定时间,线程都在一个应用程序域中执行。
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.