应用程序域为隔离正在运行的应用程序提供了一种灵活而安全的方法。

应用程序域通常由运行库宿主创建和操作。有时,您可能希望应用程序以编程方式与应用程序域交互,例如想在不停止应用程序运行的情况下卸载某个组件时。

应用程序域使应用程序以及应用程序的数据彼此分离,有助于提高安全性。单个进程可以运行多个应用程序域,并具有在单独进程中所存在的隔离级别。在单个进程中运行多个应用程序提高了服务器伸缩性。

下面的代码示例创建一个新的应用程序域,然后加载并执行以前生成的程序集 HelloWorld.exe,该程序集存储在驱动器 C 上。

C# CopyCode image复制代码
static void Main()
{
    // Create an Application Domain:
    System.AppDomain newDomain = System.AppDomain.CreateDomain("NewApplicationDomain");

    // Load and execute an assembly:
    newDomain.ExecuteAssembly(@"c:\HelloWorld.exe");

    // Unload the application domain:
    System.AppDomain.Unload(newDomain);
}

Expand 图像应用程序域概述

Expand 图像相关章节

Expand 图像C# 语言规范

Expand image请参见