다음을 통해 공유


AppDomain.Unload 메서드

지정한 응용 프로그램 도메인을 언로드합니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Shared Sub Unload ( _
    domain As AppDomain _
)
‘사용 방법
Dim domain As AppDomain

AppDomain.Unload(domain)
public static void Unload (
    AppDomain domain
)
public:
static void Unload (
    AppDomain^ domain
)
public static void Unload (
    AppDomain domain
)
public static function Unload (
    domain : AppDomain
)

매개 변수

  • domain
    언로드할 응용 프로그램 도메인입니다.

예외

예외 형식 조건

ArgumentNullException

domain이 Null 참조(Visual Basic의 경우 Nothing)인 경우

CannotUnloadAppDomainException

domain을 언로드할 수 없는 경우

설명

.NET Framework 버전 2.0에는 응용 프로그램 도메인 언로드 전용 스레드가 있습니다. 이 스레드를 사용하면 특히 .NET Framework이 호스팅된 경우 안전성이 향상됩니다. 스레드가 Unload를 호출하면 대상 도메인이 언로드되도록 표시됩니다. 그러면 전용 스레드가 도메인의 언로드를 시도하고 도메인의 모든 스레드가 중단됩니다. 스레드가 비관리 코드를 실행하거나 finally 블록을 실행하고 있는 등의 이유로 중단되지 않는 경우 일정한 시간이 지난 후 원래 Unload를 호출한 스레드에서 CannotUnloadAppDomainException이 throw됩니다. 중단할 수 없는 스레드가 결국 종료되면 대상 도메인은 언로드되지 않습니다. 따라서 .NET Framework 버전 2.0에서는 실행 중인 스레드를 종료시키지 못할 수 있으므로 domain이 언로드되지 않을 수도 있습니다.

참고

종료자에서 호출하는 경우처럼 Unload를 호출하면 CannotUnloadAppDomainException이 즉시 발생할 수도 있습니다.

domain의 스레드는 스레드에서 ThreadAbortException을 throw하는 Abort 메서드를 사용하여 종료됩니다. 스레드는 즉시 종료되어야 하지만 finally 절 내에서 일정하지 않은 시간 동안 계속 실행될 수도 있습니다.

버전 호환성

.NET Framework 버전 1.0 및 1.1에서 Unload를 호출한 스레드가 domain 내부에서 실행 중인 경우 다른 스레드에서 언로드 작업을 수행하기 시작합니다. domain을 언로드할 수 없는 경우 Unload를 호출한 원래 스레드가 아닌 해당 스레드에서 CannotUnloadAppDomainException이 throw됩니다. 그러나 Unload를 호출한 스레드가 domain 외부에서 실행 중인 경우 해당 스레드에 예외가 전달됩니다.

예제

Imports System
Imports System.Reflection
Imports System.Security.Policy 'for evidence object

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 'Main 
End Class 'ADUnload
using System;
using System.Reflection;
using System.Security.Policy;  //for evidence object
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.");
        }
        
    }
    
}
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." );
   }

}
import System.*;
import System.Reflection.*;
import System.Security.Policy.*; //for evidence object

class ADUnload
{
    public static void main(String[] args)
    {
        // Create evidence for the new appdomain.
        Evidence adEvidence = AppDomain.get_CurrentDomain().get_Evidence();

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

        Console.WriteLine("Host domain: " 
            + AppDomain.get_CurrentDomain().get_FriendlyName());
        Console.WriteLine("child domain: " + domain.get_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.get_FriendlyName());
        }
        catch (AppDomainUnloadedException e) {
            Console.WriteLine("The appdomain MyDomain does not exist.");
        }
    } //main
} //ADUnload

.NET Framework 보안

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0에서 지원

참고 항목

참조

AppDomain 클래스
AppDomain 멤버
System 네임스페이스