Transaction.EnlistVolatile 메서드

정의

트랜잭션에 참여할 일시적 리소스 관리자를 참여시킵니다.

오버로드

EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

트랜잭션에 참여하기 위해 2단계 커밋을 지원하는 일시적 리소스 관리자를 등록합니다.

EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

트랜잭션에 참여할 1단계 커밋 최적화를 지원하는 일시적 리소스 관리자를 참여시킵니다.

설명

휘발성 리소스 관리자는 참여 중인 트랜잭션을 완료하지 못하여 복구할 수 없습니다. 휘발성 및 지속성 리소스 및 리소스를 등록하는 방법에 대한 자세한 내용은 Resource Manager 구현을 참조하세요. 리소스 관리자가 커밋 알림에 응답하고 커밋을 준비하는 방법에 대한 자세한 내용은 Single-Phase 및 다단계에서 트랜잭션 커밋을 참조하세요.

EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

트랜잭션에 참여하기 위해 2단계 커밋을 지원하는 일시적 리소스 관리자를 등록합니다.

public:
 System::Transactions::Enlistment ^ EnlistVolatile(System::Transactions::IEnlistmentNotification ^ enlistmentNotification, System::Transactions::EnlistmentOptions enlistmentOptions);
public:
 System::Transactions::Enlistment ^ EnlistVolatile(System::Transactions::IEnlistmentNotification ^ notification, System::Transactions::EnlistmentOptions options);
public System.Transactions.Enlistment EnlistVolatile (System.Transactions.IEnlistmentNotification enlistmentNotification, System.Transactions.EnlistmentOptions enlistmentOptions);
public System.Transactions.Enlistment EnlistVolatile (System.Transactions.IEnlistmentNotification notification, System.Transactions.EnlistmentOptions options);
member this.EnlistVolatile : System.Transactions.IEnlistmentNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
member this.EnlistVolatile : System.Transactions.IEnlistmentNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
Public Function EnlistVolatile (enlistmentNotification As IEnlistmentNotification, enlistmentOptions As EnlistmentOptions) As Enlistment
Public Function EnlistVolatile (notification As IEnlistmentNotification, options As EnlistmentOptions) As Enlistment

매개 변수

enlistmentNotificationnotification
IEnlistmentNotification

2단계 커밋 알림을 받기 위해 IEnlistmentNotification 인터페이스를 구현하는 개체입니다.

enlistmentOptionsoptions
EnlistmentOptions

리소스 관리자가 준비 단계 동안 추가 작업을 수행하려는 경우 EnlistDuringPrepareRequired입니다.

반환

Enlistment

인리스트먼트를 설명하는 Enlistment 개체입니다.

예제

다음 예제에서는 인터페이스의 IEnlistmentNotification 구현 뿐만 아니라 메서드를 사용 하 여 트랜잭션에 참가자로 개체를 등록 합니다 EnlistVolatile .

static void Main(string[] args)
{
    try
    {
        using (TransactionScope scope = new TransactionScope())
        {
        
            //Create an enlistment object
            myEnlistmentClass myElistment = new myEnlistmentClass();

            //Enlist on the current transaction with the enlistment object
            Transaction.Current.EnlistVolatile(myElistment, EnlistmentOptions.None);

            //Perform transactional work here.

            //Call complete on the TransactionScope based on console input
                            ConsoleKeyInfo c;
            while(true)
                            {
                Console.Write("Complete the transaction scope? [Y|N] ");
                c = Console.ReadKey();
                Console.WriteLine();
        
                                    if ((c.KeyChar == 'Y') || (c.KeyChar == 'y'))
                {
                    scope.Complete();
                    break;
                }
                else if ((c.KeyChar == 'N') || (c.KeyChar == 'n'))
                {
                    break;
                }
            }
        }
    }
    catch (System.Transactions.TransactionException ex)
    {
        Console.WriteLine(ex);
    }
    catch
    {
        Console.WriteLine("Cannot complete transaction");
        throw;
    }
}

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 Shared Sub Main()
        Try
            Using scope As TransactionScope = New TransactionScope()

                'Create an enlistment object
                Dim myEnlistmentClass As New EnlistmentClass

                'Enlist on the current transaction with the enlistment object
                Transaction.Current.EnlistVolatile(myEnlistmentClass, EnlistmentOptions.None)

                'Perform transactional work here.

                'Call complete on the TransactionScope based on console input
                Dim c As ConsoleKeyInfo
                While (True)
                    Console.Write("Complete the transaction scope? [Y|N] ")
                    c = Console.ReadKey()
                    Console.WriteLine()
                    If (c.KeyChar = "Y") Or (c.KeyChar = "y") Then
                        scope.Complete()
                        Exit While
                    ElseIf ((c.KeyChar = "N") Or (c.KeyChar = "n")) Then
                        Exit While
                    End If
                End While
            End Using
        Catch ex As TransactionException
            Console.WriteLine(ex)
        Catch
            Console.WriteLine("Cannot complete transaction")
            Throw
        End Try
    End Sub
End Class

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

설명

휘발성 리소스 관리자는 참여 중인 트랜잭션을 완료하지 못하여 복구할 수 없습니다. 트랜잭션에서 지속성 인리스트먼트를 가져오려면 메서드를 EnlistDurable 사용합니다.

이 메서드를 통해 트랜잭션에 참여하도록 등록한 리소스 관리자는 인터페이스에 정의된 메서드에 IEnlistmentNotification 해당하는 2단계 커밋 알림을 받습니다.

적용 대상

EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

트랜잭션에 참여할 1단계 커밋 최적화를 지원하는 일시적 리소스 관리자를 참여시킵니다.

public:
 System::Transactions::Enlistment ^ EnlistVolatile(System::Transactions::ISinglePhaseNotification ^ singlePhaseNotification, System::Transactions::EnlistmentOptions enlistmentOptions);
public:
 System::Transactions::Enlistment ^ EnlistVolatile(System::Transactions::ISinglePhaseNotification ^ notification, System::Transactions::EnlistmentOptions options);
public System.Transactions.Enlistment EnlistVolatile (System.Transactions.ISinglePhaseNotification singlePhaseNotification, System.Transactions.EnlistmentOptions enlistmentOptions);
public System.Transactions.Enlistment EnlistVolatile (System.Transactions.ISinglePhaseNotification notification, System.Transactions.EnlistmentOptions options);
member this.EnlistVolatile : System.Transactions.ISinglePhaseNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
member this.EnlistVolatile : System.Transactions.ISinglePhaseNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
Public Function EnlistVolatile (singlePhaseNotification As ISinglePhaseNotification, enlistmentOptions As EnlistmentOptions) As Enlistment
Public Function EnlistVolatile (notification As ISinglePhaseNotification, options As EnlistmentOptions) As Enlistment

매개 변수

singlePhaseNotificationnotification
ISinglePhaseNotification

1단계 커밋과 2단계 커밋 알림을 받을 수 있어야 하는 ISinglePhaseNotification 인터페이스를 구현하는 개체입니다.

enlistmentOptionsoptions
EnlistmentOptions

리소스 관리자가 준비 단계 동안 추가 작업을 수행하려는 경우 EnlistDuringPrepareRequired입니다.

반환

Enlistment

인리스트먼트를 설명하는 Enlistment 개체입니다.

설명

휘발성 리소스 관리자는 참여 중인 트랜잭션을 완료하지 못하여 복구할 수 없습니다. 트랜잭션에서 지속성 인리스트먼트를 가져오려면 이 메서드를 EnlistDurable 사용합니다. 휘발성 및 지속성 리소스에 대한 자세한 내용과 리소스를 등록하는 방법은 Resource Manager 구현을 참조하세요. 리소스 관리자가 커밋 알림에 응답하고 커밋을 준비하는 방법에 대한 자세한 내용은 Single-Phase 및 다단계에서 트랜잭션 커밋을 참조하세요.

리소스 관리자 구현이 이 메서드에 참여하더라도 단일 단계 커밋을 수신한다는 보장은 없습니다. 트랜잭션 관리자는 두 단계 커밋 알림을 대신 보낼 수 있습니다. 단일 단계 커밋 최적화에 대한 자세한 내용은 단일 단계 커밋 및 승격 가능한 단일 단계 알림을 사용하여 최적화를 참조하세요.

추가 정보

적용 대상