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

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Thread.EndCriticalRegion メソッドの意味・解説 

Thread.EndCriticalRegion メソッド

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

スレッドの中止または処理されない例外の影響が現在のタスクだけに及ぶコード領域に実行が入ることをホストに通知します。

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

Public Shared Sub EndCriticalRegion
Thread.EndCriticalRegion
public static void EndCriticalRegion
 ()
public:
static void EndCriticalRegion ()
public static void EndCriticalRegion
 ()
public static function EndCriticalRegion
 ()
解説解説
メモメモ

このメソッドに適用される HostProtectionAttribute 属性の Resources プロパティの値は、Synchronization または ExternalThreading です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。

Microsoft® SQL Server "Yukon" などの共通言語ランタイム (CLR: Common Language Runtime) のホストは、重大なコード領域でのエラーと重大でないコード領域でのエラーに対して異なるポリシーを設定できます。重大な領域とは、スレッドの中止または処理されない例外の影響が現在のタスク以外にも及ぶ可能性がある領域です。これに対し、重大でないコード領域内での中止またはエラーは、エラーが発生したタスクだけに影響します。

たとえば、ロックを保持している間にメモリを割り当てるタスクがあると仮定します。メモリ割り当てが失敗した場合、AppDomain の安定性を確保するためには現在のタスクを中止するだけでは不十分です。これは、同じロックを待機している他のタスクがそのドメイン内に存在する可能性があるためです。現在のタスクが終了した場合に、他のタスクがデッドロック状態になる可能性があります。

重大な領域で障害が発生した場合、潜在的に不安定な状態で実行を継続する危険を冒すよりも AppDomain 全体をアンロードすることをホストが決定することがあります。コードが重大な領域に入ることをホストに通知するには、BeginCriticalRegion を呼び出します。重大でないコード領域に実行が戻るときには、EndCriticalRegion を呼び出します。

SQL Server "Yukon" で実行するコード内でこのメソッドを使用するには、ホストの保護レベルを最大にしてコードを実行する必要があります。

使用例使用例

BeginCriticalRegion メソッドおよび EndCriticalRegion メソッドを使用してコード ブロックを重大な領域と重大でない領域に分割する例を次に示します。

Imports System.Threading

Public Class MyUtility
    Public Sub PerformTask() 
        ' Code in this region can be aborted without affecting
        ' other tasks.
        '
        Thread.BeginCriticalRegion()
        '
        ' The host might decide to unload the application domain
        ' if a failure occurs in this code region.
        '
        Thread.EndCriticalRegion()
        ' Code in this region can be aborted without affecting
        ' other tasks.
    End Sub
End Class 
using System.Threading;

public class MyUtility
{
    public void PerformTask()
    {
        // Code in this region can be aborted without affecting
        // other tasks.
        //
        Thread.BeginCriticalRegion();
        //
        // The host might decide to unload the application domain
        // if a failure occurs in this code region.
        //
        Thread.EndCriticalRegion();
        //
        // Code in this region can be aborted without affecting
        // other tasks.
    }
}
using namespace System::Threading;

public ref class MyUtility
{
public:
   void PerformTask()
   {
      // Code in this region can be aborted without affecting
      // other tasks.
      //
      Thread::BeginCriticalRegion();
      //
      // The host might decide to unload the application domain
      // if a failure occurs in this code region.
      //
      Thread::EndCriticalRegion();
      //
      // Code in this region can be aborted without affecting
      // other tasks.
   }
};
import System.Threading.*;
import System.Threading.Thread;

public class MyUtility
{
    public void PerformTask()
    {
        // Code in this region can be aborted without affecting
        // other tasks.
        //
        Thread.BeginCriticalRegion();

        //
        // The host might decide to unload the application domain
        // if a failure occurs in this code region.
        //
        Thread.EndCriticalRegion();
        // Code in this region can be aborted without affecting
        // other tasks.
    } //PerformTask
} //MyUtility
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「Thread.EndCriticalRegion メソッド」の関連用語

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

   

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



Thread.EndCriticalRegion メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS