AppDomain.Unload メソッドとは? わかりやすく解説

AppDomain.Unload メソッド

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

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

domainnull 参照 (Visual Basic では Nothing) です。

CannotUnloadAppDomainException

domainアンロードできませんでした

解説解説

.NET Framework Version 2.0 では、アプリケーション ドメインアンロードするための専用スレッド使用されます。このバージョン.NET Frameworkホストされた環境では、これによって信頼性向上しますスレッドから Unload呼び出されると、ターゲット ドメインアンロード対象としてマークされます。専用スレッドによって、そのドメインアンロード試みられ、そのドメインすべてのスレッド中止されます。アンマネージ コード実行中である、または、finally ブロック実行中である、などの理由からスレッド終了できなかった場合は、一定時間の経過後に、Unload呼び出しスレッドCannotUnloadAppDomainExceptionスローさます。最終的にスレッド終了できなかった場合ターゲット ドメインアンロードされません。このように.NET Framework Version 2.0 では、実行中のスレッド中止できない場合があるため、domain確実にアンロードされるという保証はありません。

メモメモ

一部ケースでは、Unload呼び出した直後CannotUnloadAppDomainException発生する場合あります (ファイナライザから呼び出した場合など)。

domain 内のスレッドは、Abort メソッド使って終了され、そのスレッドで ThreadAbortException がスローさます。スレッドはすぐに終了する必要がありますが、finally 句が実行されている間は継続される場合あります。この時間予測できません。

バージョン互換性

.NET Framework Version 1.0 および 1.1 では、Unload呼び出したスレッドdomain 内で実行中の場合アンロード処理を実行するための別のスレッド開始されます。domainアンロードできなかった場合は、このスレッドCannotUnloadAppDomainExceptionスローされ、Unload呼び出し元のスレッドではスローされません。ただし、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 のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「AppDomain.Unload メソッド」の関連用語

AppDomain.Unload メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



AppDomain.Unload メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS