Freigeben über


DependentTransaction Klasse

Definition

Beschreibt einen Klon einer Transaktion, die eine Garantie bereitstellt, dass die Transaktion erst zugesichert werden kann, wenn die Anwendung in Bezug auf die Arbeit an der Transaktion zur Ruhe kommt. Diese Klasse kann nicht vererbt werden.

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
Vererbung
DependentTransaction
Attribute

Beispiele

Das folgende Beispiel zeigt, wie Sie eine abhängige Transaktion erstellen.

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

Hinweise

Dies DependentTransaction ist ein Klon eines Transaction Objekts, das mit der DependentClone Methode erstellt wurde. Der einzige Zweck besteht darin, der Anwendung die Möglichkeit zu geben, ruhen zu lassen und sicherzustellen, dass die Transaktion nicht ausgeführt werden kann, während die Arbeit noch an der Transaktion ausgeführt wird (z. B. in einem Arbeitsthread).

Wenn die Arbeit innerhalb der geklonten Transaktion abgeschlossen ist und bereit für das Commit ist, kann sie den Ersteller der Transaktion mithilfe der Complete Methode informieren. So können Sie die Konsistenz und Richtigkeit der Daten beibehalten.

Die DependentCloneOption Aufzählung wird verwendet, um das Verhalten beim Commit zu bestimmen. Diese Verhaltenssteuerung ermöglicht es einer Anwendung, zur Ruhe zu kommen, und bietet Parallelitätsunterstützung.

Eigenschaften

Name Beschreibung
IsolationLevel

Ruft die Isolationsebene der Transaktion ab.

(Geerbt von Transaction)
PromoterType

Identifiziert das Format des byte[] von der Promote-Methode zurückgegebenen Formats eindeutig, wenn die Transaktion höhergestuft wird.

(Geerbt von Transaction)
TransactionInformation

Ruft zusätzliche Informationen zu einer Transaktion ab.

(Geerbt von Transaction)

Methoden

Name Beschreibung
Clone()

Erstellt einen Klon der Transaktion.

(Geerbt von Transaction)
Complete()

Versucht, die abhängige Transaktion abzuschließen.

DependentClone(DependentCloneOption)

Erstellt einen abhängigen Klon der Transaktion.

(Geerbt von Transaction)
Dispose()

Gibt die Ressourcen frei, die vom Objekt gehalten werden.

(Geerbt von Transaction)
EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions)

Enlists a durable resource manager that supports two phase commit to part in a transaction.

(Geerbt von Transaction)
EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions)

Enlists a durable resource manager that supports single phase commit optimization to part in a transaction.

(Geerbt von Transaction)
EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid)

Enlists a resource manager that has an internal transaction using a promotable single phase enlistment (PSPE).

(Geerbt von Transaction)
EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification)

Enlists a resource manager that has an internal transaction using a promotable single phase enlistment (PSPE).

(Geerbt von Transaction)
EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)

Enlists a volatile resource manager that supports two phase commit to part in a transaction.

(Geerbt von Transaction)
EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)

Enlists a volatile resource manager that supports single phase commit optimization to part in a transaction.

(Geerbt von Transaction)
Equals(Object)

Bestimmt, ob diese Transaktion und das angegebene Objekt gleich sind.

(Geerbt von Transaction)
GetHashCode()

Gibt den Hashcode für diese Instanz zurück.

(Geerbt von Transaction)
GetPromotedToken()

Ruft die byte[] von der Promote Methode zurückgegebene, wenn die Transaktion höhergestuft wird.

(Geerbt von Transaction)
GetType()

Ruft die Type der aktuellen Instanz ab.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie der aktuellen Object.

(Geerbt von Object)
PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions)

Fördert und listet einen dauerhaften Ressourcenmanager auf, der zwei Phasen-Commit für die Teilnahme an einer Transaktion unterstützt.

(Geerbt von Transaction)
Rollback()

Rollback (Abgebrochen) die Transaktion zurück.

(Geerbt von Transaction)
Rollback(Exception)

Rollback (Abgebrochen) die Transaktion zurück.

(Geerbt von Transaction)
SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid)

Legt den vom Nicht-MSDTC-Promoter generierten verteilten Transaktionsbezeichner fest.

(Geerbt von Transaction)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)

Ereignisse

Name Beschreibung
TransactionCompleted

Gibt an, dass die Transaktion abgeschlossen ist.

(Geerbt von Transaction)

Explizite Schnittstellenimplementierungen

Name Beschreibung
ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Ruft einen SerializationInfo mit den Daten ab, die zum Serialisieren dieser Transaktion erforderlich sind.

(Geerbt von Transaction)

Gilt für:

Threadsicherheit

Dieser Typ ist threadsicher.