AppDomain 類別

定義

表示應用程式定義域,也就是應用程式執行的獨立環境。Represents an application domain, which is an isolated environment where applications execute. 這個類別無法被繼承。This class cannot be inherited.

public ref class AppDomain sealed : MarshalByRefObject, _AppDomain, System::Security::IEvidenceFactory
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class AppDomain : MarshalByRefObject, _AppDomain, System.Security.IEvidenceFactory
type AppDomain = class
    inherit MarshalByRefObject
    interface _AppDomain
    interface IEvidenceFactory
Public NotInheritable Class AppDomain
Inherits MarshalByRefObject
Implements _AppDomain, IEvidenceFactory
繼承
屬性
實作

範例

這個範例示範如何建立新的 AppDomain、在該新的 AppDomain中具現化型別,以及與該型別的物件通訊。This example shows how to create a new AppDomain, instantiate a type in that new AppDomain, and communicate with that type's object. 此外,這個範例會示範如何卸載 AppDomain 導致物件進行垃圾收集。In addition, this example shows how to unload the AppDomain causing the object to be garbage collected.

using namespace System;
using namespace System::Reflection;
using namespace System::Threading;
using namespace System::Security::Policy;

// Because this class is derived from MarshalByRefObject, a proxy 
// to a MarshalByRefType object can be returned across an AppDomain 
// boundary.
ref class MarshalByRefType : MarshalByRefObject
{
public:
    //  Call this method via a proxy.
    void SomeMethod(String^ callingDomainName)
    {
        // Get this AppDomain's settings and display some of them.
        AppDomainSetup^ ads = AppDomain::CurrentDomain->SetupInformation;
        Console::WriteLine("AppName={0}, AppBase={1}, ConfigFile={2}", 
            ads->ApplicationName, 
            ads->ApplicationBase, 
            ads->ConfigurationFile
        );

        // Display the name of the calling AppDomain and the name 
        // of the second domain.
        // NOTE: The application's thread has transitioned between 
        // AppDomains.
        Console::WriteLine("Calling from '{0}' to '{1}'.", 
            callingDomainName, 
            Thread::GetDomain()->FriendlyName
        );
    };
};

void main()
{
    // Get and display the friendly name of the default AppDomain.
    String^ callingDomainName = Thread::GetDomain()->FriendlyName;
    Console::WriteLine(callingDomainName);

    // Get and display the full name of the EXE assembly.
    String^ exeAssembly = Assembly::GetEntryAssembly()->FullName;
    Console::WriteLine(exeAssembly);

    // Construct and initialize settings for a second AppDomain.
    AppDomainSetup^ ads = gcnew AppDomainSetup();
    ads->ApplicationBase = AppDomain::CurrentDomain->BaseDirectory;

    ads->DisallowBindingRedirects = false;
    ads->DisallowCodeDownload = true;
    ads->ConfigurationFile = 
        AppDomain::CurrentDomain->SetupInformation->ConfigurationFile;

    // Create the second AppDomain.
    AppDomain^ ad2 = AppDomain::CreateDomain("AD #2", 
        AppDomain::CurrentDomain->Evidence, ads);

    // Create an instance of MarshalbyRefType in the second AppDomain. 
    // A proxy to the object is returned.
    MarshalByRefType^ mbrt = 
        (MarshalByRefType^) ad2->CreateInstanceAndUnwrap(
            exeAssembly, 
            MarshalByRefType::typeid->FullName
        );

    // Call a method on the object via the proxy, passing the 
    // default AppDomain's friendly name in as a parameter.
    mbrt->SomeMethod(callingDomainName);

    // Unload the second AppDomain. This deletes its object and 
    // invalidates the proxy object.
    AppDomain::Unload(ad2);
    try
    {
        // Call the method again. Note that this time it fails 
        // because the second AppDomain was unloaded.
        mbrt->SomeMethod(callingDomainName);
        Console::WriteLine("Sucessful call.");
    }
    catch(AppDomainUnloadedException^)
    {
        Console::WriteLine("Failed call; this is expected.");
    }
}

/* This code produces output similar to the following: 

AppDomainX.exe
AppDomainX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
AppName=, AppBase=C:\AppDomain\bin, ConfigFile=C:\AppDomain\bin\AppDomainX.exe.config
Calling from 'AppDomainX.exe' to 'AD #2'.
Failed call; this is expected.
 */
using System;
using System.Reflection;
using System.Threading;

class Module1
{
    public static void Main()
    {
        // Get and display the friendly name of the default AppDomain.
        string callingDomainName = Thread.GetDomain().FriendlyName;
        Console.WriteLine(callingDomainName);

        // Get and display the full name of the EXE assembly.
        string exeAssembly = Assembly.GetEntryAssembly().FullName;
        Console.WriteLine(exeAssembly);

        // Construct and initialize settings for a second AppDomain.
        AppDomainSetup ads = new AppDomainSetup();
        ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;

        ads.DisallowBindingRedirects = false;
        ads.DisallowCodeDownload = true;
        ads.ConfigurationFile = 
            AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

        // Create the second AppDomain.
        AppDomain ad2 = AppDomain.CreateDomain("AD #2", null, ads);

        // Create an instance of MarshalbyRefType in the second AppDomain. 
        // A proxy to the object is returned.
        MarshalByRefType mbrt = 
            (MarshalByRefType) ad2.CreateInstanceAndUnwrap(
                exeAssembly, 
                typeof(MarshalByRefType).FullName
            );

        // Call a method on the object via the proxy, passing the 
        // default AppDomain's friendly name in as a parameter.
        mbrt.SomeMethod(callingDomainName);

        // Unload the second AppDomain. This deletes its object and 
        // invalidates the proxy object.
        AppDomain.Unload(ad2);
        try
        {
            // Call the method again. Note that this time it fails 
            // because the second AppDomain was unloaded.
            mbrt.SomeMethod(callingDomainName);
            Console.WriteLine("Sucessful call.");
        }
        catch(AppDomainUnloadedException)
        {
            Console.WriteLine("Failed call; this is expected.");
        }
    }
}

// Because this class is derived from MarshalByRefObject, a proxy 
// to a MarshalByRefType object can be returned across an AppDomain 
// boundary.
public class MarshalByRefType : MarshalByRefObject
{
    //  Call this method via a proxy.
    public void SomeMethod(string callingDomainName)
    {
        // Get this AppDomain's settings and display some of them.
        AppDomainSetup ads = AppDomain.CurrentDomain.SetupInformation;
        Console.WriteLine("AppName={0}, AppBase={1}, ConfigFile={2}", 
            ads.ApplicationName, 
            ads.ApplicationBase, 
            ads.ConfigurationFile
        );

        // Display the name of the calling AppDomain and the name 
        // of the second domain.
        // NOTE: The application's thread has transitioned between 
        // AppDomains.
        Console.WriteLine("Calling from '{0}' to '{1}'.", 
            callingDomainName, 
            Thread.GetDomain().FriendlyName
        );
    }
}

/* This code produces output similar to the following: 

AppDomainX.exe
AppDomainX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
AppName=, AppBase=C:\AppDomain\bin, ConfigFile=C:\AppDomain\bin\AppDomainX.exe.config
Calling from 'AppDomainX.exe' to 'AD #2'.
Failed call; this is expected.
 */
Imports System.Reflection
Imports System.Threading

Module Module1
    Sub Main()

        ' Get and display the friendly name of the default AppDomain.
        Dim callingDomainName As String = Thread.GetDomain().FriendlyName
        Console.WriteLine(callingDomainName)

        ' Get and display the full name of the EXE assembly.
        Dim exeAssembly As String = [Assembly].GetEntryAssembly().FullName
        Console.WriteLine(exeAssembly)

        ' Construct and initialize settings for a second AppDomain.
        Dim ads As New AppDomainSetup()
        ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory
        ads.DisallowBindingRedirects = False
        ads.DisallowCodeDownload = True
        ads.ConfigurationFile = _
            AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

        ' Create the second AppDomain.
        Dim ad2 As AppDomain = AppDomain.CreateDomain("AD #2", Nothing, ads)

        ' Create an instance of MarshalbyRefType in the second AppDomain. 
        ' A proxy to the object is returned.
        Dim mbrt As MarshalByRefType = CType( _
            ad2.CreateInstanceAndUnwrap(exeAssembly, _
                 GetType(MarshalByRefType).FullName), MarshalByRefType)

        ' Call a method on the object via the proxy, passing the default 
        ' AppDomain's friendly name in as a parameter.
        mbrt.SomeMethod(callingDomainName)

        ' Unload the second AppDomain. This deletes its object and 
        ' invalidates the proxy object.
        AppDomain.Unload(ad2)
        Try
            ' Call the method again. Note that this time it fails because 
            ' the second AppDomain was unloaded.
            mbrt.SomeMethod(callingDomainName)
            Console.WriteLine("Sucessful call.")
        Catch e As AppDomainUnloadedException
            Console.WriteLine("Failed call; this is expected.")
        End Try

    End Sub
End Module

' Because this class is derived from MarshalByRefObject, a proxy 
' to a MarshalByRefType object can be returned across an AppDomain 
' boundary.
Public Class MarshalByRefType
    Inherits MarshalByRefObject

    '  Call this method via a proxy.
    Public Sub SomeMethod(ByVal callingDomainName As String)

        ' Get this AppDomain's settings and display some of them.
        Dim ads As AppDomainSetup = AppDomain.CurrentDomain.SetupInformation
        Console.WriteLine("AppName={0}, AppBase={1}, ConfigFile={2}", _
            ads.ApplicationName, ads.ApplicationBase, ads.ConfigurationFile)

        ' Display the name of the calling AppDomain and the name 
        ' of the second domain.
        ' NOTE: The application's thread has transitioned between 
        ' AppDomains.
        Console.WriteLine("Calling from '{0}' to '{1}'.", _
            callingDomainName, Thread.GetDomain().FriendlyName)
    End Sub
End Class

'This code produces output similar to the following:
' 
' AppDomainX.exe
' AppDomainX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
' AppName=, AppBase=C:\AppDomain\bin, ConfigFile=C:\AppDomain\bin\AppDomainX.exe.config
' Calling from 'AppDomainX.exe' to 'AD #2'.
' Failed call; this is expected.

備註

應用程式域(以 AppDomain 物件表示)可提供執行 managed 程式碼的隔離、卸載和安全性界限。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. 如果執行工作的 AppDomain 狀態變得不穩定,則可以卸載 AppDomain,而不會影響進程。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. 使用這項技術,將偶爾使用大型 Dll 的長時間執行進程的工作集降到最低。Use this technique to minimize the working set of long-running processes that occasionally use large DLLs.

注意

在 .NET Core 上,AppDomain 的執行會受到設計的限制,而且不會提供隔離、卸載或安全性界限。On .NET Core, the AppDomain implementation is limited by design and does not provide isolation, unloading, or security boundaries. 針對 .NET Core,只有一個 AppDomainFor .NET Core, there is exactly one AppDomain. 隔離和卸載是透過 AssemblyLoadContext提供。Isolation and unloading are provided through AssemblyLoadContext. 安全性界限應由進程界限和適當的遠端處理技術提供。Security boundaries should be provided by process boundaries and appropriate remoting techniques.

多個應用程式域可以在單一進程中執行;不過,應用程式域和執行緒之間並沒有一對一的相互關聯。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.

應用程式域是使用 CreateDomain 方法建立的。Application domains are created using the CreateDomain method. AppDomain 實例是用來載入和執行元件(Assembly)。AppDomain instances are used to load and execute assemblies (Assembly). AppDomain 不再使用時,可以將它卸載。When an AppDomain is no longer in use, it can be unloaded.

AppDomain 類別會執行一組事件,讓應用程式在載入元件時、在卸載應用程式域時,或擲回未處理的例外狀況時回應。The AppDomain class implements a set of events that enable applications to respond when an assembly is loaded, when an application domain will be unloaded, or when an unhandled exception is thrown.

如需使用應用程式域的詳細資訊,請參閱應用程式域For more information on using application domains, see Application Domains.

這個類別會執行 MarshalByRefObject_AppDomainIEvidenceFactory 介面。This class implements the MarshalByRefObject, _AppDomain, and IEvidenceFactory interfaces.

您絕對不應該為 AppDomain 物件建立可遠端包裝函式。You should never create a remotable wrapper for an AppDomain object. 這麼做可以發行該 AppDomain的遠端參考,將 CreateInstance 的方法公開給遠端存取,並有效地終結該 AppDomain的代碼啟用安全性。Doing so could publish a remote reference to that AppDomain, exposing methods such as CreateInstance to remote access and effectively destroying code access security for that AppDomain. 連線至遠端 AppDomain 的惡意用戶端,可以取得 AppDomain 本身可存取之任何資源的存取權。Malicious clients connecting to the remoted AppDomain could obtain access to any resource the AppDomain itself has access to. 請勿針對延伸 MarshalByRefObject 的任何類型建立可遠端包裝函式,並且會執行可能由惡意用戶端用來略過安全性系統的方法。Do not create remotable wrappers for any type that extends MarshalByRefObject and that implements methods that could be used by malicious clients to bypass the security system.

警告

AppDomainSetup.DisallowCodeDownload 屬性的預設值為 [false]。The default value for the AppDomainSetup.DisallowCodeDownload property is false. 此設定對於服務是不安全的。This setting is unsafe for services. 若要防止服務下載部分信任的程式碼,請將此屬性設定為 trueTo prevent services from downloading partially trusted code, set this property to true.

屬性

ActivationContext

取得目前應用程式定義域的啟動內容。Gets the activation context for the current application domain.

ApplicationIdentity

取得應用程式定義域中的應用程式之識別。Gets the identity of the application in the application domain.

ApplicationTrust

取得資訊,以描述授與應用程式的權限,以及該應用程式是否有允許其執行的信任層級。Gets information describing permissions granted to an application and whether the application has a trust level that allows it to run.

BaseDirectory

取得組件解析程式 (Resolver) 用來探查組件的基底目錄。Gets the base directory that the assembly resolver uses to probe for assemblies.

CurrentDomain

取得目前 Thread 的目前應用程式定義域。Gets the current application domain for the current Thread.

DomainManager

取得在已經初始化應用程式定義域時,由主應用程式提供的定義域管理員。Gets the domain manager that was provided by the host when the application domain was initialized.

DynamicDirectory

取得組件解析程式用來探查動態建立之組件的目錄。Gets the directory that the assembly resolver uses to probe for dynamically created assemblies.

Evidence

取得與此應用程式定義域相關聯的 EvidenceGets the Evidence associated with this application domain.

FriendlyName

取得應用程式定義域的易記名稱。Gets the friendly name of this application domain.

Id

取得可唯一識別處理序中之應用程式定義域的整數。Gets an integer that uniquely identifies the application domain within the process.

IsFullyTrusted

取得值,該值指出載入目前應用程式定義域中的組件是否在完全信任情況下執行。Gets a value that indicates whether assemblies that are loaded into the current application domain execute with full trust.

IsHomogenous

取得值,這個值表示目前應用程式定義域是否會授與一組權限給所有載入該應用程式定義域中的組件。Gets a value that indicates whether the current application domain has a set of permissions that is granted to all assemblies that are loaded into the application domain.

MonitoringIsEnabled

取得或設定值,這個值表示是否對目前處理序啟用應用程式定義域的 CPU 和記憶體監視。Gets or sets a value that indicates whether CPU and memory monitoring of application domains is enabled for the current process. 一旦對處理序啟用監視,就不能停用。Once monitoring is enabled for a process, it cannot be disabled.

MonitoringSurvivedMemorySize

取得自上次回收作業後存留下來,且已知正由目前應用程式定義域參考之位元組的數目。Gets the number of bytes that survived the last collection and that are known to be referenced by the current application domain.

MonitoringSurvivedProcessMemorySize

針對處理序中的所有應用程式定義域,取得自上次回收作業存留下來的位元組總數。Gets the total bytes that survived from the last collection for all application domains in the process.

MonitoringTotalAllocatedMemorySize

取得應用程式定義域自其建立後已配置之所有記憶體的總大小 (以位元組為單位),但不減去已回收的記憶體。Gets the total size, in bytes, of all memory allocations that have been made by the application domain since it was created, without subtracting memory that has been collected.

MonitoringTotalProcessorTime

取得自處理程序啟動後,所有執行緒在目前應用程式定義域中執行時用掉的處理器時間總計。Gets the total processor time that has been used by all threads while executing in the current application domain, since the process started.

PermissionSet

取得沙箱應用程式定義域的權限集。Gets the permission set of a sandboxed application domain.

RelativeSearchPath

取得組件解析程式應該在其中探查私用組件的路徑,此路徑位於基底目錄下。Gets the path under the base directory where the assembly resolver should probe for private assemblies.

SetupInformation

取得這個執行個體的應用程式定義域組態資訊。Gets the application domain configuration information for this instance.

ShadowCopyFiles

取得是否已設定應用程式定義域以進行檔案陰影複製的指示。Gets an indication whether the application domain is configured to shadow copy files.

方法

AppendPrivatePath(String)

將指定的目錄名稱附加至私用 (Private) 路徑清單。Appends the specified directory name to the private path list.

ApplyPolicy(String)

在套用原則之後傳回組件的顯示名稱。Returns the assembly display name after policy has been applied.

ClearPrivatePath()

將指定私用組件位置的路徑重設為空字串 ("")。Resets the path that specifies the location of private assemblies to the empty string ("").

ClearShadowCopyPath()

將含有陰影複製的組件目錄清單重設為空字串 ("")。Resets the list of directories containing shadow copied assemblies to the empty string ("").

CreateComInstanceFrom(String, String)

建立指定 COM 類型的新執行個體。Creates a new instance of a specified COM type. 指定包含組件 (包含類型和類型名稱) 之檔案名稱的參數。Parameters specify the name of a file that contains an assembly containing the type and the name of the type.

CreateComInstanceFrom(String, String, Byte[], AssemblyHashAlgorithm)

建立指定 COM 類型的新執行個體。Creates a new instance of a specified COM type. 指定包含組件 (包含類型和類型名稱) 之檔案名稱的參數。Parameters specify the name of a file that contains an assembly containing the type and the name of the type.

CreateDomain(String)

建立具有指定名稱的新應用程式定義域。Creates a new application domain with the specified name.

CreateDomain(String, Evidence)

使用提供的辨識項,建立具有指定名稱的新應用程式定義域。Creates a new application domain with the given name using the supplied evidence.

CreateDomain(String, Evidence, AppDomainSetup)

使用指定名稱、辨識項和應用程式定義域安裝資訊,建立新的應用程式定義域。Creates a new application domain using the specified name, evidence, and application domain setup information.

CreateDomain(String, Evidence, AppDomainSetup, PermissionSet, StrongName[])

使用指定之名稱、辨識項、應用程式定義域設定資訊、預設權限集合及完全信任的組件陣列,建立新的應用程式定義域。Creates a new application domain using the specified name, evidence, application domain setup information, default permission set, and array of fully trusted assemblies.

CreateDomain(String, Evidence, String, String, Boolean)

使用辨識項、應用程式基底路徑、相對搜尋路徑和指定是否要將組件的陰影複本載入應用程式定義域的參數,建立具有指定名稱的新應用程式定義域。Creates a new application domain with the given name, using evidence, application base path, relative search path, and a parameter that specifies whether a shadow copy of an assembly is to be loaded into the application domain.

CreateDomain(String, Evidence, String, String, Boolean, AppDomainInitializer, String[])

使用辨識項、應用程式基底路徑、相對搜尋路徑和指定是否要將組件的陰影複本載入應用程式定義域的參數,建立具有指定名稱的新應用程式定義域。Creates a new application domain with the given name, using evidence, application base path, relative search path, and a parameter that specifies whether a shadow copy of an assembly is to be loaded into the application domain. 指定當初始化應用程式定義域時所叫用的回呼方法,以及要傳遞給該回呼方法的字串引數陣列。Specifies a callback method that is invoked when the application domain is initialized, and an array of string arguments to pass the callback method.

CreateInstance(String, String)

建立指定組件中所定義之指定類型的新執行個體。Creates a new instance of the specified type defined in the specified assembly.

CreateInstance(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

建立指定組件中所定義之指定類型的新執行個體。Creates a new instance of the specified type defined in the specified assembly. 參數會指定繫結器、繫結旗標、建構函式引數、用來解譯引數的特定文化特性資訊,以及選擇性的啟動屬性。Parameters specify a binder, binding flags, constructor arguments, culture-specific information used to interpret arguments, and optional activation attributes.

CreateInstance(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)

建立指定組件中所定義之指定類型的新執行個體。Creates a new instance of the specified type defined in the specified assembly. 參數會指定繫結器 (Binder)、繫結旗標、建構函式引數、用來解譯引數的特定文化特性資訊、啟動屬性,以及建立類型的授權。Parameters specify a binder, binding flags, constructor arguments, culture-specific information used to interpret arguments, activation attributes, and authorization to create the type.

CreateInstance(String, String, Object[])

建立指定組件中所定義之指定類型的新執行個體。Creates a new instance of the specified type defined in the specified assembly. 參數會指定啟動屬性的陣列。A parameter specifies an array of activation attributes.

CreateInstanceAndUnwrap(String, String)

建立指定類型的新執行個體。Creates a new instance of the specified type. 參數會指定定義類型所在的組件和類型的名稱。Parameters specify the assembly where the type is defined, and the name of the type.

CreateInstanceAndUnwrap(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

藉由指定是否忽略類型名稱的大小寫、用於選取要建立之類型的繫結屬性和繫結器、建構函式的引數、文化特性,以及啟動屬性,為指定之組件中定義的指定類型,建立新的執行個體。Creates a new instance of the specified type defined in the specified assembly, specifying whether the case of the type name is ignored; the binding attributes and the binder that are used to select the type to be created; the arguments of the constructor; the culture; and the activation attributes.

CreateInstanceAndUnwrap(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)

建立指定類型的新執行個體。Creates a new instance of the specified type. 參數會指定類型的名稱,以及如何尋找和建立它。Parameters specify the name of the type, and how it is found and created.

CreateInstanceAndUnwrap(String, String, Object[])

建立指定類型的新執行個體。Creates a new instance of the specified type. 參數會指定定義類型所在的組件、類型的名稱和啟動屬性的陣列。Parameters specify the assembly where the type is defined, the name of the type, and an array of activation attributes.

CreateInstanceFrom(String, String)

建立指定組件檔案中所定義之指定類型的新執行個體。Creates a new instance of the specified type defined in the specified assembly file.

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

建立指定組件檔案中所定義之指定類型的新執行個體。Creates a new instance of the specified type defined in the specified assembly file.

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)

建立指定組件檔案中所定義之指定類型的新執行個體。Creates a new instance of the specified type defined in the specified assembly file.

CreateInstanceFrom(String, String, Object[])

建立指定組件檔案中所定義之指定類型的新執行個體。Creates a new instance of the specified type defined in the specified assembly file.

CreateInstanceFromAndUnwrap(String, String)

建立指定組件檔案中所定義之指定類型的新執行個體。Creates a new instance of the specified type defined in the specified assembly file.

CreateInstanceFromAndUnwrap(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

藉由指定是否忽略類型名稱的大小寫、用於選取要建立之類型的繫結屬性和繫結器、建構函式的引數、文化特性,以及啟動屬性,為指定之組件檔中定義的指定類型,建立新的執行個體。Creates a new instance of the specified type defined in the specified assembly file, specifying whether the case of the type name is ignored; the binding attributes and the binder that are used to select the type to be created; the arguments of the constructor; the culture; and the activation attributes.

CreateInstanceFromAndUnwrap(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)

建立指定組件檔案中所定義之指定類型的新執行個體。Creates a new instance of the specified type defined in the specified assembly file.

CreateInstanceFromAndUnwrap(String, String, Object[])

建立指定組件檔案中所定義之指定類型的新執行個體。Creates a new instance of the specified type defined in the specified assembly file.

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess)

使用指定的名稱和存取模式定義動態組件。Defines a dynamic assembly with the specified name and access mode.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, Evidence)

使用指定的名稱、存取模式和辨識項來定義動態組件。Defines a dynamic assembly using the specified name, access mode, and evidence.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, Evidence, PermissionSet, PermissionSet, PermissionSet)

使用指定的名稱、存取模式、辨識項和權限要求來定義動態組件。Defines a dynamic assembly using the specified name, access mode, evidence, and permission requests.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>)

使用指定的名稱、存取模式及自訂屬性來定義動態組件。Defines a dynamic assembly with the specified name, access mode, and custom attributes.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, IEnumerable<CustomAttributeBuilder>, SecurityContextSource)

定義動態組件,這個動態組件具有指定的名稱、存取模式和自訂模式,並且使用指定的來源做為安全性內容。Defines a dynamic assembly with the specified name, access mode, and custom attributes, and using the specified source for its security context.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, PermissionSet, PermissionSet, PermissionSet)

使用指定的名稱、存取模式和權限要求來定義動態組件。Defines a dynamic assembly using the specified name, access mode, and permission requests.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String)

使用指定的名稱、存取模式和儲存目錄來定義動態組件。Defines a dynamic assembly using the specified name, access mode, and storage directory.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Boolean, IEnumerable<CustomAttributeBuilder>)

使用指定的名稱、存取模式、儲存目錄和同步處理選項來定義動態組件。Defines a dynamic assembly using the specified name, access mode, storage directory, and synchronization option.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Evidence)

使用指定的名稱、存取模式、儲存目錄和辨識項來定義動態組件。Defines a dynamic assembly using the specified name, access mode, storage directory, and evidence.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet)

使用指定的名稱、存取模式、儲存目錄、辨識項和權限要求來定義動態組件。Defines a dynamic assembly using the specified name, access mode, storage directory, evidence, and permission requests.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean)

使用指定的名稱、存取模式、儲存目錄、辨識項、權限要求和同步選項來定義動態組件。Defines a dynamic assembly using the specified name, access mode, storage directory, evidence, permission requests, and synchronization option.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, Evidence, PermissionSet, PermissionSet, PermissionSet, Boolean, IEnumerable<CustomAttributeBuilder>)

使用指定的名稱、存取模式、儲存目錄、辨識項、權限要求、同步選項及自訂屬性來定義動態組件。Defines a dynamic assembly with the specified name, access mode, storage directory, evidence, permission requests, synchronization option, and custom attributes.

DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess, String, PermissionSet, PermissionSet, PermissionSet)

使用指定的名稱、存取模式、儲存目錄和權限要求來定義動態組件。Defines a dynamic assembly using the specified name, access mode, storage directory, and permission requests.

DoCallBack(CrossAppDomainDelegate)

在指定的委派所識別的其他應用程式定義域中執行程式碼。Executes the code in another application domain that is identified by the specified delegate.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
ExecuteAssembly(String)

執行包含在指定檔案中的組件。Executes the assembly contained in the specified file.

ExecuteAssembly(String, Evidence)

使用指定的辨識項,執行包含在指定檔案中的組件。Executes the assembly contained in the specified file, using the specified evidence.

ExecuteAssembly(String, Evidence, String[])

使用指定的辨識項和引數,執行包含在指定檔案中的組件。Executes the assembly contained in the specified file, using the specified evidence and arguments.

ExecuteAssembly(String, Evidence, String[], Byte[], AssemblyHashAlgorithm)

使用指定的辨識項、引數、雜湊值和雜湊演算法,執行包含在指定檔案中的組件。Executes the assembly contained in the specified file, using the specified evidence, arguments, hash value, and hash algorithm.

ExecuteAssembly(String, String[])

使用指定的引數,執行包含在指定檔案中的組件。Executes the assembly contained in the specified file, using the specified arguments.

ExecuteAssembly(String, String[], Byte[], AssemblyHashAlgorithm)

使用指定的引數、雜湊值和雜湊演算法,執行包含在指定檔案中的組件。Executes the assembly contained in the specified file, using the specified arguments, hash value, and hash algorithm.

ExecuteAssemblyByName(AssemblyName, Evidence, String[])

使用指定之辨識項和引數,執行需提供 AssemblyName 的組件。Executes the assembly given an AssemblyName, using the specified evidence and arguments.

ExecuteAssemblyByName(AssemblyName, String[])

使用指定的引數,執行具有指定之 AssemblyName 的組件。Executes the assembly given an AssemblyName, using the specified arguments.

ExecuteAssemblyByName(String)

執行需提供其顯示名稱的組件。Executes an assembly given its display name.

ExecuteAssemblyByName(String, Evidence)

使用指定之辨識項,執行需提供其顯示名稱的組件。Executes an assembly given its display name, using the specified evidence.

ExecuteAssemblyByName(String, Evidence, String[])

使用指定之辨識項和引數,執行需提供其顯示名稱的組件。Executes the assembly given its display name, using the specified evidence and arguments.

ExecuteAssemblyByName(String, String[])

使用指定的引數,執行具有指定之顯示名稱的組件。Executes the assembly given its display name, using the specified arguments.

GetAssemblies()

取得已載入至這個應用程式定義域之執行內容的組件。Gets the assemblies that have been loaded into the execution context of this application domain.

GetCurrentThreadId()

取得目前的執行緒識別項。Gets the current thread identifier.

GetData(String)

針對指定之名稱取得儲存在目前應用程式定義域中的值。Gets the value stored in the current application domain for the specified name.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetType()

取得目前執行個體的類型。Gets the type of the current instance.

InitializeLifetimeService()

藉由防止建立租用 (Lease),為 AppDomain 提供無限的存留期。Gives the AppDomain an infinite lifetime by preventing a lease from being created.

IsCompatibilitySwitchSet(String)

取得可為 Null 的布林值,這個值表示是否已設定任何相容性參數,如果已設定,是否已設定指定的相容性參數。Gets a nullable Boolean value that indicates whether any compatibility switches are set, and if so, whether the specified compatibility switch is set.

IsDefaultAppDomain()

傳回值,指出應用程式定義域是否為該處理程序的預設應用程式定義域。Returns a value that indicates whether the application domain is the default application domain for the process.

IsFinalizingForUnload()

指示這個應用程式定義域是否正在卸載,以及其包含的物件是否正在由 Common Language Runtime 進行最終處理。Indicates whether this application domain is unloading, and the objects it contains are being finalized by the common language runtime.

Load(AssemblyName)

載入提供了 AssemblyNameAssemblyLoads an Assembly given its AssemblyName.

Load(AssemblyName, Evidence)

載入提供了 AssemblyNameAssemblyLoads an Assembly given its AssemblyName.

Load(Byte[])

載入具備通用物件檔案格式 (COFF) 影像 (包含發出的 Assembly) 的 AssemblyLoads the Assembly with a common object file format (COFF) based image containing an emitted Assembly.

Load(Byte[], Byte[])

載入具備通用物件檔案格式 (COFF) 影像 (包含發出的 Assembly) 的 AssemblyLoads the Assembly with a common object file format (COFF) based image containing an emitted Assembly. 也會載入代表 Assembly 符號且未經處理的位元組。The raw bytes representing the symbols for the Assembly are also loaded.

Load(Byte[], Byte[], Evidence)

載入具備通用物件檔案格式 (COFF) 影像 (包含發出的 Assembly) 的 AssemblyLoads the Assembly with a common object file format (COFF) based image containing an emitted Assembly. 也會載入代表 Assembly 符號且未經處理的位元組。The raw bytes representing the symbols for the Assembly are also loaded.

Load(String)

載入提供了顯示名稱的 AssemblyLoads an Assembly given its display name.

Load(String, Evidence)

載入提供了顯示名稱的 AssemblyLoads an Assembly given its display name.

MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
ReflectionOnlyGetAssemblies()

傳回已經載入到應用程式定義域之僅限反映的內容之組件。Returns the assemblies that have been loaded into the reflection-only context of the application domain.

SetAppDomainPolicy(PolicyLevel)

為這個應用程式定義域建立安全性原則層級。Establishes the security policy level for this application domain.

SetCachePath(String)

將指定的目錄路徑建立為陰影複製組件的所在位置。Establishes the specified directory path as the location where assemblies are shadow copied.

SetData(String, Object)

將指定值指派至指定的應用程式定義域屬性。Assigns the specified value to the specified application domain property.

SetData(String, Object, IPermission)

將指定之值指派給指定之應用程式定義域屬性,而當擷取這個屬性時,有指定向呼叫端要求的權限。Assigns the specified value to the specified application domain property, with a specified permission to demand of the caller when the property is retrieved.

SetDynamicBase(String)

建立指定的目錄路徑,做為存放及存取動態產生檔案之子目錄的基底目錄。Establishes the specified directory path as the base directory for subdirectories where dynamically generated files are stored and accessed.

SetPrincipalPolicy(PrincipalPolicy)

如果執行緒在這個應用程式定義域執行時嘗試繫結至主體,則指定主體和識別 (Identity) 物件應該如何附加至執行緒。Specifies how principal and identity objects should be attached to a thread if the thread attempts to bind to a principal while executing in this application domain.

SetShadowCopyFiles()

開啟陰影複製。Turns on shadow copying.

SetShadowCopyPath(String)

建立指定的目錄路徑,做為要陰影複製的組件位置。Establishes the specified directory path as the location of assemblies to be shadow copied.

SetThreadPrincipal(IPrincipal)

如果執行緒在這個應用程式定義域中執行時嘗試繫結至預設的主體,則設定預設的主體物件附加至執行緒。Sets the default principal object to be attached to threads if they attempt to bind to a principal while executing in this application domain.

ToString()

取得字串表示,其中包含應用程式定義域及任何內容原則的易記名稱。Obtains a string representation that includes the friendly name of the application domain and any context policies.

Unload(AppDomain)

卸載指定的應用程式定義域。Unloads the specified application domain.

事件

AssemblyLoad

發生於載入組件時。Occurs when an assembly is loaded.

AssemblyResolve

發生於組件解析失敗時。Occurs when the resolution of an assembly fails.

DomainUnload

發生於將要卸載 AppDomain 時。Occurs when an AppDomain is about to be unloaded.

FirstChanceException

發生於執行階段在呼叫堆疊中搜尋應用程式定義域的例外狀況處理常式之前,在 Managed 程式碼中擲回例外狀況時。Occurs when an exception is thrown in managed code, before the runtime searches the call stack for an exception handler in the application domain.

ProcessExit

發生於預設應用程式定義域的父處理程序結束時。Occurs when the default application domain's parent process exits.

ReflectionOnlyAssemblyResolve

發生於僅限反映之內容中的組件解析失敗時。Occurs when the resolution of an assembly fails in the reflection-only context.

ResourceResolve

發生於資源的解析失敗時 (原因是因為該資源在組件中不是有效連結或內嵌的資源)。Occurs when the resolution of a resource fails because the resource is not a valid linked or embedded resource in the assembly.

TypeResolve

發生於類型解析失敗時。Occurs when the resolution of a type fails.

UnhandledException

發生於未攔截到例外狀況時。Occurs when an exception is not caught.

明確介面實作

_AppDomain.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

_AppDomain.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can then be used to get the type information for an interface.

_AppDomain.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

_AppDomain.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

適用於

另請參閱