Thread.EndCriticalRegion メソッド
アセンブリ: mscorlib (mscorlib.dll 内)


![]() |
---|
このメソッドに適用される 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

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からThread.EndCriticalRegion メソッドを検索する場合は、下記のリンクをクリックしてください。

- Thread.EndCriticalRegion メソッドのページへのリンク