DependentTransaction 클래스

정의

애플리케이션이 트랜잭션의 작업을 중지할 때까지 트랜잭션이 커밋되지 않도록 하는 트랜잭션 복제본에 대해 설명합니다. 이 클래스는 상속될 수 없습니다.

public ref class DependentTransaction sealed : System::Transactions::Transaction
public sealed class DependentTransaction : System.Transactions.Transaction
[System.Serializable]
public sealed class DependentTransaction : System.Transactions.Transaction
type DependentTransaction = class
    inherit Transaction
[<System.Serializable>]
type DependentTransaction = class
    inherit Transaction
Public NotInheritable Class DependentTransaction
Inherits Transaction
상속
DependentTransaction
특성

예제

다음 예제에서는 종속 트랜잭션을 만드는 방법을 보여줍니다.

static void Main(string[] args)
{
    try
    {
        using (TransactionScope scope = new TransactionScope())
        {
            // Perform transactional work here.

            //Queue work item
            ThreadPool.QueueUserWorkItem(new WaitCallback(WorkerThread), Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete));

            //Display transaction information
            Console.WriteLine("Transaction information:");
            Console.WriteLine("ID:             {0}", Transaction.Current.TransactionInformation.LocalIdentifier);
            Console.WriteLine("status:         {0}", Transaction.Current.TransactionInformation.Status);
            Console.WriteLine("isolationlevel: {0}", Transaction.Current.IsolationLevel);

            //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'))
                {
                    //Call complete on the scope
                    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;
    }
}

private static void WorkerThread(object transaction)
{
    //Create a DependentTransaction from the object passed to the WorkerThread
    DependentTransaction dTx = (DependentTransaction)transaction;

    //Sleep for 1 second to force the worker thread to delay
    Thread.Sleep(1000);

    //Pass the DependentTransaction to the scope, so that work done in the scope becomes part of the transaction passed to the worker thread
    using (TransactionScope ts = new TransactionScope(dTx))
    {
        //Perform transactional work here.

        //Call complete on the transaction scope
        ts.Complete();
    }

    //Call complete on the dependent transaction
    dTx.Complete();
}
Public Shared Sub Main()
    Try
        Using scope As TransactionScope = New TransactionScope()

            'Perform transactional work here.

            'Queue work item
            ThreadPool.QueueUserWorkItem(AddressOf WorkerThread, Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete))

            'Display transaction information
            Console.WriteLine("Transaction information:")
            Console.WriteLine("ID:             {0}", Transaction.Current.TransactionInformation.LocalIdentifier)
            Console.WriteLine("status:         {0}", Transaction.Current.TransactionInformation.Status)
            Console.WriteLine("isolationlevel: {0}", Transaction.Current.IsolationLevel)

            '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

Public Shared Sub WorkerThread(ByVal myTransaction As Object)

    'Create a DependentTransaction from the object passed to the WorkerThread
    Dim dTx As DependentTransaction
    dTx = CType(myTransaction, DependentTransaction)

    'Sleep for 1 second to force the worker thread to delay
    Thread.Sleep(1000)

    'Pass the DependentTransaction to the scope, so that work done in the scope becomes part of the transaction passed to the worker thread
    Using ts As TransactionScope = New TransactionScope(dTx)
        'Perform transactional work here.

        'Call complete on the transaction scope
        ts.Complete()
    End Using

    'Call complete on the dependent transaction
    dTx.Complete()
End Sub

설명

DependentTransaction 메서드를 Transaction 사용하여 만든 개체의 복제본입니다 DependentClone . Rest 작업 (예: 작업자 스레드)에 트랜잭션 작업이 수행 되는 동안 트랜잭션이 커밋할 수 없습니다는 보장을 제공 하도록 애플리케이션을 허용 하도록 유일한 목적은 것입니다.

복제된 트랜잭션 내에서 수행된 작업이 마침내 완료되고 커밋할 준비가 되면 메서드를 사용하여 Complete 트랜잭션 작성자에게 알릴 수 있습니다. 따라서 데이터의 일관성과 정확성을 유지할 수 있습니다.

DependentCloneOption 열거형은 커밋의 동작을 확인하는 데 사용됩니다. 이 동작은 컨트롤 정지할 동시성 지원을 제공 하는 것은 물론 애플리케이션을 허용 합니다. 이 열거형을 사용하는 방법에 대한 자세한 내용은 DependentTransaction을 사용하여 동시성 관리를 참조하세요.

속성

IsolationLevel

트랜잭션의 격리 수준을 가져옵니다.

(다음에서 상속됨 Transaction)
PromoterType

트랜잭션을 승격할 때 확장 메서드에서 반환한 byte[] 의 형식을 고유하게 식별합니다.

(다음에서 상속됨 Transaction)
TransactionInformation

트랜잭션에 대한 추가 정보를 검색합니다.

(다음에서 상속됨 Transaction)

메서드

Clone()

트랜잭션의 복제본을 만듭니다.

(다음에서 상속됨 Transaction)
Complete()

종속 트랜잭션을 완료하려고 시도합니다.

DependentClone(DependentCloneOption)

트랜잭션의 종속 복제본을 만듭니다.

(다음에서 상속됨 Transaction)
Dispose()

개체에서 보유하는 리소스를 해제합니다.

(다음에서 상속됨 Transaction)
EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions)

트랜잭션에 참여할 2단계 커밋을 지원하는 영속적 리소스 관리자를 참여시킵니다.

(다음에서 상속됨 Transaction)
EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions)

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

(다음에서 상속됨 Transaction)
EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification)

PSPE(Promotable Single Phase Enlistment)를 통해 내부 트랜잭션이 있는 리소스 관리자를 등록합니다.

(다음에서 상속됨 Transaction)
EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid)

PSPE(Promotable Single Phase Enlistment)를 통해 내부 트랜잭션이 있는 리소스 관리자를 등록합니다.

(다음에서 상속됨 Transaction)
EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

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

(다음에서 상속됨 Transaction)
EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

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

(다음에서 상속됨 Transaction)
Equals(Object)

이 트랜잭션과 지정된 개체가 같은지 여부를 확인합니다.

(다음에서 상속됨 Transaction)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Transaction)
GetPromotedToken()

트랜잭션이 byte[] 승격될 때 메서드에서 Promote 반환된 를 가져옵니다.

(다음에서 상속됨 Transaction)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions)

트랜잭션에 참여할 2단계 커밋을 지원하는 영속적 리소스 관리자를 승격 및 참여시킵니다.

(다음에서 상속됨 Transaction)
Rollback()

트랜잭션을 롤백(중단)합니다.

(다음에서 상속됨 Transaction)
Rollback(Exception)

트랜잭션을 롤백(중단)합니다.

(다음에서 상속됨 Transaction)
SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid)

비MSDTC 프로모터를 통해 생성된 분산 트랜잭션 식별자를 설정합니다.

(다음에서 상속됨 Transaction)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

이벤트

TransactionCompleted

트랜잭션이 완료되었음을 나타냅니다.

(다음에서 상속됨 Transaction)

명시적 인터페이스 구현

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

이 트랜잭션을 serialize하는 데 필요한 데이터가 있는 SerializationInfo를 가져옵니다.

(다음에서 상속됨 Transaction)

적용 대상

스레드 보안

이 형식은 스레드로부터 안전합니다.

추가 정보