Freigeben über


Abrufen von Setupinformationen aus einer Anwendungsdomäne

Hinweis

Dieser Artikel gilt für das .NET Framework. Er gilt nicht für neuere Implementierungen von .NET, einschließlich .NET 6 und höherer Versionen.

Jede Instanz einer Anwendungsdomäne besteht sowohl aus Eigenschaften als auch aus AppDomainSetup-Informationen. Sie können Setupinformationen aus einer Anwendungsdomäne mit der Klasse System.AppDomain abrufen. Diese Klasse stellt mehrere Member zur Verfügung, die Konfigurierungsinformationen zu Anwendungsdomänen abrufen.

Sie können das Objekt AppDomainSetup für die Anwendungsdomäne abfragen, um Setupinformationen zu erhalten, die der Erstellung an die Domäne übergeben wurden.

Im folgenden Beispiel wird eine neue Anwendungsdomäne erstellt, und anschließend werden mehrere Memberwerte an die Konsole ausgegeben.

using namespace System;
using namespace System::Reflection;

ref class AppDomain3
{
public:
    static void Main()
    {
        // Create the new application domain.
        AppDomain^ domain = AppDomain::CreateDomain("MyDomain", nullptr);

        // Output to the console.
        Console::WriteLine("Host domain: " + AppDomain::CurrentDomain->FriendlyName);
        Console::WriteLine("New domain: " + domain->FriendlyName);
        Console::WriteLine("Application base is: " + domain->BaseDirectory);
        Console::WriteLine("Relative search path is: " + domain->RelativeSearchPath);
        Console::WriteLine("Shadow copy files is set to: " + domain->ShadowCopyFiles);
        AppDomain::Unload(domain);
    }
};

int main()
{
    AppDomain3::Main();
}
using System;
using System.Reflection;

class AppDomain3
{
    public static void Main()
    {
        // Create the new application domain.
        AppDomain domain = AppDomain.CreateDomain("MyDomain", null);

        // Output to the console.
        Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
        Console.WriteLine("New domain: " + domain.FriendlyName);
        Console.WriteLine("Application base is: " + domain.BaseDirectory);
        Console.WriteLine("Relative search path is: " + domain.RelativeSearchPath);
        Console.WriteLine("Shadow copy files is set to: " + domain.ShadowCopyFiles);
        AppDomain.Unload(domain);
    }
}
Imports System.Reflection

Class AppDomain3
    Public Shared Sub Main()
        ' Create the new application domain.
        Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing)

        ' Output to the console.
        Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName)
        Console.WriteLine("New domain: " + domain.FriendlyName)
        Console.WriteLine("Application base is: " + domain.BaseDirectory)
        Console.WriteLine("Relative search path is: " + domain.RelativeSearchPath)
        Console.WriteLine("Shadow copy files is set to: " + domain.ShadowCopyFiles)
        AppDomain.Unload(domain)
    End Sub
End Class

In folgendem Beispielen werden Setupinformationen für die Anwendungsdomäne festgelegt und anschließend abgerufen. AppDomain.SetupInformation.ApplicationBase ruft die Konfigurationsinformationen ab.

using namespace System;
using namespace System::Reflection;

ref class AppDomain5
{
public:
    static void Main()
    {
        // Application domain setup information.
        AppDomainSetup^ domaininfo = gcnew AppDomainSetup();
        domaininfo->ApplicationBase = "f:\\work\\development\\latest";
        domaininfo->ConfigurationFile = "f:\\work\\development\\latest\\appdomain5.exe.config";

        // Creates the application domain.
        AppDomain^ domain = AppDomain::CreateDomain("MyDomain", nullptr, domaininfo);

        // Write the application domain information to the console.
        Console::WriteLine("Host domain: " + AppDomain::CurrentDomain->FriendlyName);
        Console::WriteLine("Child domain: " + domain->FriendlyName);
        Console::WriteLine();
        Console::WriteLine("Application base is: " + domain->SetupInformation->ApplicationBase);
        Console::WriteLine("Configuration file is: " + domain->SetupInformation->ConfigurationFile);

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

int main()
{
    AppDomain5::Main();
}
using System;
using System.Reflection;

class AppDomain5
{
    public static void Main()
    {
        // Application domain setup information.
        AppDomainSetup domaininfo = new AppDomainSetup();
        domaininfo.ApplicationBase = "f:\\work\\development\\latest";
        domaininfo.ConfigurationFile = "f:\\work\\development\\latest\\appdomain5.exe.config";

        // Creates the application domain.
        AppDomain domain = AppDomain.CreateDomain("MyDomain", null, domaininfo);

        // Write the application domain information to the console.
        Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
        Console.WriteLine("Child domain: " + domain.FriendlyName);
        Console.WriteLine();
        Console.WriteLine("Application base is: " + domain.SetupInformation.ApplicationBase);
        Console.WriteLine("Configuration file is: " + domain.SetupInformation.ConfigurationFile);

        // Unloads the application domain.
        AppDomain.Unload(domain);
    }
}
Imports System.Reflection

Class AppDomain5
    Public Shared Sub Main()
        ' Application domain setup information.
        Dim domaininfo As New AppDomainSetup()
        domaininfo.ApplicationBase = "f:\work\development\latest"
        domaininfo.ConfigurationFile = "f:\work\development\latest\appdomain5.exe.config"

        ' Creates the application domain.
        Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing, domaininfo)

        ' Write the application domain information to the console.
        Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName)
        Console.WriteLine("Child domain: " + domain.FriendlyName)
        Console.WriteLine()
        Console.WriteLine("Application base is: " + domain.SetupInformation.ApplicationBase)
        Console.WriteLine("Configuration file is: " + domain.SetupInformation.ConfigurationFile)

        ' Unloads the application domain.
        AppDomain.Unload(domain)
    End Sub
End Class

Siehe auch