AppDomain.Unload(AppDomain) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
주의
Creating and unloading AppDomains is not supported and throws an exception.
지정된 애플리케이션 도메인을 언로드합니다.
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);
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}")>]
static member Unload : AppDomain -> unit
static member Unload : AppDomain -> unit
Public Shared Sub Unload (domain As AppDomain)
매개 변수
- domain
- AppDomain
언로드할 애플리케이션 도메인입니다.
- 특성
예외
domain은 null입니다.
언로드 프로세스 중에 오류가 발생했습니다.
예제
다음 코드 예제에서는 애플리케이션 도메인을 언로드하는 방법을 보여줍니다.
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가 호스트되는 경우 안정성이 향상됩니다. 스레드가 호출 Unload되면 대상 도메인이 언로드로 표시됩니다. 전용 스레드가 도메인을 언로드하려고 시도하고 도메인의 모든 스레드가 중단됩니다. 예를 들어 스레드가 관리되지 않는 코드를 실행 중이거나 블록을 실행 finally 하기 때문에 중단되지 않는 경우, 일정 기간 CannotUnloadAppDomainException 후에는 원래 호출 Unload된 스레드에서 throw됩니다. 중단될 수 없는 스레드가 결국 종료되면 대상 도메인이 언로드되지 않습니다.
domain 따라서 실행 중인 스레드를 종료할 수 없으므로 언로드가 보장되지 않습니다.
메모
경우에 따라 호출하면 종료자에서 호출 Unload 되는 경우와 같이 즉시 CannotUnloadAppDomainException호출이 발생합니다.
스레드는 스레드에서 domain throw하는 메서드를 Abort 사용하여 ThreadAbortException 종료됩니다. 스레드는 즉시 종료되어야 하지만 절에서 finally 예측할 수 없는 시간 동안 계속 실행할 수 있습니다.