AppDomain.Unload メソッド
名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文


.NET Framework Version 2.0 では、アプリケーション ドメインをアンロードするための専用のスレッドが使用されます。このバージョンの .NET Framework がホストされた環境では、これによって信頼性が向上します。スレッドから Unload が呼び出されると、ターゲット ドメインがアンロードの対象としてマークされます。専用のスレッドによって、そのドメインのアンロードが試みられ、そのドメインのすべてのスレッドが中止されます。アンマネージ コードを実行中である、または、finally ブロックを実行中である、などの理由からスレッドを終了できなかった場合は、一定時間の経過後に、Unload の呼び出し元スレッドで CannotUnloadAppDomainException がスローされます。最終的にスレッドを終了できなかった場合、ターゲット ドメインはアンロードされません。このように、.NET Framework Version 2.0 では、実行中のスレッドを中止できない場合があるため、domain が確実にアンロードされるという保証はありません。
![]() |
---|
一部のケースでは、Unload を呼び出した直後に CannotUnloadAppDomainException が発生する場合があります (ファイナライザから呼び出した場合など)。 |
domain 内のスレッドは、Abort メソッドを使って終了され、そのスレッドで ThreadAbortException がスローされます。スレッドはすぐに終了する必要がありますが、finally 句が実行されている間は継続される場合があります。この時間は予測できません。
バージョンの互換性
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


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- AppDomain.Unload メソッドのページへのリンク