AppDomain.Unload メソッド

指定したアプリケーション ドメインをアンロードします。

Public Shared Sub Unload( _
   ByVal domain As AppDomain _)
[C#]
public static void Unload(AppDomaindomain);
[C++]
public: static void Unload(AppDomain* domain);
[JScript]
public static function Unload(
   domain : AppDomain);

パラメータ

  • domain
    アンロードするアプリケーション ドメイン。

例外

例外の種類 条件
ArgumentNullException domain が null 参照 (Visual Basic では Nothing) です。
CannotUnloadAppDomainException domain をアンロードできませんでした。

解説

実行中のスレッドの終了は難しい場合があるため、 domain が実際にアンロードされるまでには長い時間がかかることがあります。

Unload を呼び出したスレッドが domain で実行中の場合、アンロード処理を実行するための別のスレッドが開始されます。 domain をアンロードできない場合は、 Unload を呼び出した元のスレッドではなく、この別のスレッドに対して CannotUnloadAppDomainException のインスタンスがスローされます。ただし、 Unload を呼び出したスレッドが domain の外で実行されている場合は、このスレッドが例外を受け取ります。

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

[C#] 
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.");
        }
        
    }
    
}

[C++] 
#using <mscorlib.dll>

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(S"MyDomain", adevidence);

   Console::WriteLine(S"Host domain: {0}", AppDomain::CurrentDomain->FriendlyName);
   Console::WriteLine(S"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(S"child domain: {0}", domain->FriendlyName);
   } catch (AppDomainUnloadedException* /*e*/) {
      Console::WriteLine(S"The appdomain MyDomain does not exist.");
   }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard

.NET Framework セキュリティ:

参照

AppDomain クラス | AppDomain メンバ | System 名前空間