Thread.EndCriticalRegion 메서드

정의

스레드 중단 또는 처리되지 않은 예외가 현재 작업에만 영향을 주는 코드 영역이 실행될 것임을 호스트에 알립니다.

public:
 static void EndCriticalRegion();
public static void EndCriticalRegion ();
static member EndCriticalRegion : unit -> unit
Public Shared Sub EndCriticalRegion ()

예제

다음 예제에서는 BeginCriticalRegion 및 메서드를 사용 하 여 EndCriticalRegion 코드 블록을 중요 하 고 중요 하지 않은 영역으로 나누는 방법을 보여 줍니다.

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.
   }
};
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.
    }
}
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

설명

Microsoft SQL Server 2005와 같은 CLR (공용 언어 런타임)의 호스트는 중요 하 고 중요 하지 않은 코드 영역에서 발생 하는 오류에 대해 서로 다른 정책을 설정할 수 있습니다. 중요 한 지역은 스레드 중단 또는 처리 되지 않은 예외가 현재 작업으로 제한 되지 않는 것입니다. 이와 대조적으로 중요 하지 않은 코드 영역의 중단 또는 오류는 오류가 발생 한 작업에만 영향을 줍니다.

예를 들어 잠금을 보유 하는 동안 메모리를 할당 하려고 하는 작업을 고려 합니다. 메모리 할당이 실패 하는 경우의 안정성을 보장 하기 위해 현재 작업을 중단 하는 데 충분 하지 않습니다 AppDomain . 동일한 잠금에 대해 대기 하는 도메인의 다른 태스크가 있을 수 있기 때문입니다. 현재 작업이 종료 되 면 다른 작업은 교착 상태가 될 수 있습니다.

중요 한 지역에서 오류가 발생 하는 경우 호스트는 AppDomain 잠재적으로 불안정 한 상태로 실행을 계속할 수 있는 위험을 초래 하는 것이 아니라 전체를 언로드할 수 있습니다. 코드가 중요 한 영역을 입력 하 고 있음을 호스트에 알리려면를 호출 BeginCriticalRegion 합니다. EndCriticalRegion실행이 중요 하지 않은 코드 영역으로 반환 될 때를 호출 합니다.

SQL Server 2005에서 실행 되는 코드에서이 메서드를 사용 하려면 가장 높은 호스트 보호 수준에서 코드를 실행 해야 합니다.

적용 대상

추가 정보