Thread.BeginCriticalRegion 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
실행이 스레드 중단 또는 처리되지 않은 예외의 영향으로 애플리케이션 도메인의 다른 작업이 위태로울 수 있는 코드 영역을 입력하려고 한다는 것을 호스트에 알렸습니다.
public:
static void BeginCriticalRegion();
public static void BeginCriticalRegion();
static member BeginCriticalRegion : unit -> unit
Public Shared Sub BeginCriticalRegion ()
예제
다음 예제에서는 코드 블록을 중요 및 BeginCriticalRegion 중요하지 않은 영역으로 나누는 방법과 메서드를 사용하는 EndCriticalRegion 방법을 보여 줍니다.
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.
}
}
open System.Threading
let 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에서 실행되는 코드에서 이 메서드를 사용하려면 가장 높은 호스트 보호 수준에서 코드를 실행해야 합니다.