|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Application Domains in the .NET Compact Framework
Every .NET Compact Framework application runs inside in a runtime construct called an application domain, which is similar to an operating system process. The .NET Compact Framework ensures that all managed resources used by a running application are freed or returned to the host operating system when the application ends.
Application domains offer many of the advantages of processes, such as fault isolation, improved robustness, and security, without requiring support from the underlying host operating system. An application domain host starts an instance of the common language runtime and is itself native operating system code. The common language runtime can be statically or dynamically linked to the application domain host.
The .NET Compact Framework does not place restrictions on the behavior of the application domain host. The application domain host can be a simple extension to an existing interactive shell that is used to start and stop programs. On dynamic application systems like Windows, the application domain host can be an extension to the application loader so that .NET Compact Framework applications can be started and stopped using the same mechanism as a native application.
Multiple Application Domains
The .NET Compact Framework supports multiple application domains. You can specify an assembly in the constructor of a class. Then you can usemethod to start a new application domain. The new application domain loads its own copies of the common language runtime DLLs, data structures, and memory pools. Multiple application domains can exist in one operating system process.
The .NET Compact Framework does not support loading assemblies into a domain neutral code area for use by multiple application domains.
The .NET Compact Framework determines when garbage collection should be run. Garbage collection can occur in a single application domain or in all application domains. This prevents one application domain from using too much memory at the expense of others.