AppDomain.Unload(AppDomain) 메서드

정의

주의

Creating and unloading AppDomains is not supported and throws an exception.

지정한 애플리케이션 도메인을 언로드합니다.

public:
 static void Unload(AppDomain ^ domain);
public static void Unload (AppDomain domain);
[System.Obsolete("Creating and unloading AppDomains is not supported and throws an exception.", DiagnosticId="SYSLIB0024", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static void Unload (AppDomain domain);
static member Unload : AppDomain -> unit
[<System.Obsolete("Creating and unloading AppDomains is not supported and throws an exception.", DiagnosticId="SYSLIB0024", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
static member Unload : AppDomain -> unit
Public Shared Sub Unload (domain As AppDomain)

매개 변수

domain
AppDomain

언로드할 애플리케이션 도메인입니다.

특성

예외

domain이(가) null인 경우

.NET Core 및 .NET 5+ 전용: 모든 경우

또는

domain을 언로드할 수 없는 경우

언로드하는 동안 오류가 발생한 경우

예제

다음 코드 예제에는 애플리케이션 도메인을 언로드하는 방법을 보여 줍니다.

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

//for evidence Object*
int main()
{
   
   //Create evidence for the new appdomain.
   Evidence^ adevidence = AppDomain::CurrentDomain->Evidence;
   
   // Create the new application domain.
   AppDomain^ domain = AppDomain::CreateDomain( "MyDomain", adevidence );
   Console::WriteLine( "Host domain: {0}", AppDomain::CurrentDomain->FriendlyName );
   Console::WriteLine( "child domain: {0}", domain->FriendlyName );
   
   // Unload the application domain.
   AppDomain::Unload( domain );
   try
   {
      Console::WriteLine();
      
      // Note that the following statement creates an exception because the domain no longer exists.
      Console::WriteLine( "child domain: {0}", domain->FriendlyName );
   }
   catch ( AppDomainUnloadedException^ /*e*/ ) 
   {
      Console::WriteLine( "The appdomain MyDomain does not exist." );
   }

}
using System;
using System.Reflection;
using System.Security.Policy;
class ADUnload
{
    public static void Main()
    {

        //Create evidence for the new appdomain.
        Evidence adevidence = AppDomain.CurrentDomain.Evidence;

        // Create the new application domain.
        AppDomain domain = AppDomain.CreateDomain("MyDomain", adevidence);

                Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
                Console.WriteLine("child domain: " + domain.FriendlyName);
        // Unload the application domain.
        AppDomain.Unload(domain);

        try
        {
        Console.WriteLine();
        // Note that the following statement creates an exception because the domain no longer exists.
                Console.WriteLine("child domain: " + domain.FriendlyName);
        }

        catch (AppDomainUnloadedException e)
        {
        Console.WriteLine("The appdomain MyDomain does not exist.");
        }
    }
}
open System

//Create evidence for the new appdomain.
let adevidence = AppDomain.CurrentDomain.Evidence

// Create the new application domain.
let domain = AppDomain.CreateDomain("MyDomain", adevidence)

printfn $"Host domain: {AppDomain.CurrentDomain.FriendlyName}"
printfn $"child domain: {domain.FriendlyName}"
// Unload the application domain.
AppDomain.Unload domain

try
    printfn ""
    // Note that the following statement creates an exception because the domain no longer exists.
    printfn $"child domain: {domain.FriendlyName}"

with :? AppDomainUnloadedException ->
    printfn "The appdomain MyDomain does not exist."
Imports System.Reflection
Imports System.Security.Policy

Class ADUnload
   
   Public Shared Sub Main()

      'Create evidence for the new appdomain.
      Dim adevidence As Evidence = AppDomain.CurrentDomain.Evidence

      ' Create the new application domain.
      Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", adevidence)
      
      Console.WriteLine(("Host domain: " + AppDomain.CurrentDomain.FriendlyName))
      Console.WriteLine(("child domain: " + domain.FriendlyName))
      ' Unload the application domain.
      AppDomain.Unload(domain)
      
      Try
         Console.WriteLine()
         ' Note that the following statement creates an exception because the domain no longer exists.
         Console.WriteLine(("child domain: " + domain.FriendlyName))
      
      Catch e As AppDomainUnloadedException
         Console.WriteLine("The appdomain MyDomain does not exist.")
      End Try
   End Sub
End Class

설명

.NET Framework 버전 2.0 이상에는 애플리케이션 도메인 언로드 전용 스레드가 있습니다. 이렇게 하면 특히 .NET Framework 호스팅되는 경우 안정성이 향상됩니다. 스레드가 를 호출 Unload하면 대상 도메인이 언로드로 표시됩니다. 전용 스레드가 도메인을 언로드하려고 하면 도메인의 모든 스레드가 중단됩니다. 예를 들어 스레드가 관리되지 않는 코드를 실행 중이거나 블록을 CannotUnloadAppDomainException 실행 finally 중이기 때문에 중단되지 않으면 는 원래 라고 하는 Unload스레드에서 throw됩니다. 중단될 수 없는 스레드가 결국 종료되면 대상 도메인이 언로드되지 않습니다. 따라서 .NET Framework 버전 2.0 이상 domain 에서는 실행 중인 스레드를 종료할 수 없기 때문에 언로드가 보장되지 않습니다.

참고

경우에 따라 를 호출 Unload 하면 종료자에서 호출되는 경우와 같이 즉시 CannotUnloadAppDomainException가 발생합니다.

의 스레드는 스레드에서 domainAbort throw하는 메서드를 ThreadAbortException 사용하여 종료됩니다. 스레드는 즉시 종료되어야 하지만 절에서 finally 예측할 수 없는 시간 동안 계속 실행할 수 있습니다.

적용 대상

추가 정보