PreparingEnlistment.Prepared 메서드

정의

트랜잭션이 커밋될 수 있음을 나타냅니다.

public:
 void Prepared();
public void Prepared ();
member this.Prepared : unit -> unit
Public Sub Prepared ()

예제

class myEnlistmentClass : IEnlistmentNotification
{
    public void Prepare(PreparingEnlistment preparingEnlistment)
    {
        Console.WriteLine("Prepare notification received");

        //Perform transactional work

        //If work finished correctly, reply prepared
        preparingEnlistment.Prepared();

        // otherwise, do a ForceRollback
        preparingEnlistment.ForceRollback();
    }

    public void Commit(Enlistment enlistment)
    {
        Console.WriteLine("Commit notification received");

        //Do any work necessary when commit notification is received

        //Declare done on the enlistment
        enlistment.Done();
    }

    public void Rollback(Enlistment enlistment)
    {
        Console.WriteLine("Rollback notification received");

        //Do any work necessary when rollback notification is received

        //Declare done on the enlistment
        enlistment.Done();
    }

    public void InDoubt(Enlistment enlistment)
    {
        Console.WriteLine("In doubt notification received");

        //Do any work necessary when indout notification is received
        
        //Declare done on the enlistment
        enlistment.Done();
    }
}
Public Class EnlistmentClass
    Implements IEnlistmentNotification

    Public Sub Prepare(ByVal myPreparingEnlistment As PreparingEnlistment) Implements System.Transactions.IEnlistmentNotification.Prepare
        Console.WriteLine("Prepare notification received")

        'Perform transactional work

        'If work finished correctly, reply with prepared
        myPreparingEnlistment.Prepared()
    End Sub

    Public Sub Commit(ByVal myEnlistment As Enlistment) Implements System.Transactions.IEnlistmentNotification.Commit
        Console.WriteLine("Commit notification received")

        'Do any work necessary when commit notification is received

        'Declare done on the enlistment
        myEnlistment.Done()
    End Sub

    Public Sub Rollback(ByVal myEnlistment As Enlistment) Implements System.Transactions.IEnlistmentNotification.Rollback
        Console.WriteLine("Rollback notification received")

        'Do any work necessary when rollback notification is received

        'Declare done on the enlistment
        myEnlistment.Done()
    End Sub

    Public Sub InDoubt(ByVal myEnlistment As Enlistment) Implements System.Transactions.IEnlistmentNotification.InDoubt
        Console.WriteLine("In doubt notification received")

        'Do any work necessary when indout notification is received

        'Declare done on the enlistment
        myEnlistment.Done()
    End Sub
End Class

설명

2단계 커밋의 첫 번째(준비) 단계에서는 인터페이스 메서드 IEnlistmentNotification 를 구현하는 Prepare 리소스 관리자가 이 메서드를 호출하여 트랜잭션을 커밋할 수 있음을 나타냅니다.

리소스 관리자는 이 메서드를 Done 호출하기 전에 언제든지 메서드를 호출할 수 있습니다. 이렇게 함으로써 인리스트먼트는 읽기 전용 투표를 캐스팅합니다. 즉, 트랜잭션에 대한 커밋에 투표하지만 최종 결과를 받을 필요는 없습니다.

이 메서드가 인리스트먼트에 의해 호출되고 반환되기 전에 다른 스레드 또는 동일한 스레드가 롤백을 수행하는 것과 같은 Rollback 동일한 인리스트먼트 메서드를 호출할 수 있습니다. 이 메서드가 반환될 때까지 리소스 관리자 구현에서 리소스 잠금을 해제하지 않는 경우 교착 상태가 발생할 수 있습니다.

적용 대상