次の方法で共有


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 名前空間