DependentTransaction Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Beskriver en klon av en transaktion som garanterar att transaktionen inte kan checkas in förrän programmet kommer till vila angående arbetet med transaktionen. Det går inte att ärva den här klassen.
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
- Arv
- Attribut
Exempel
I följande exempel visas hur du skapar en beroende transaktion.
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
Kommentarer
DependentTransaction är en klon av ett Transaction objekt som skapats DependentClone med hjälp av metoden . Det enda syftet är att låta programmet vila och garantera att transaktionen inte kan genomföras medan arbetet fortfarande utförs på transaktionen (till exempel på en arbetstråd).
När det arbete som utförs inom den klonade transaktionen äntligen är klart och redo att genomföras kan det informera skaparen av transaktionen med hjälp Complete av metoden. På så sätt kan du bevara datas konsekvens och korrekthet.
Uppräkningen DependentCloneOption används för att fastställa beteendet vid incheckning. Med den här beteendekontrollen kan ett program vila och ge samtidighetsstöd. Mer information om hur den här uppräkningen används finns i Hantera samtidighet med DependentTransaction.
Egenskaper
| Name | Description |
|---|---|
| IsolationLevel |
Hämtar transaktionens isoleringsnivå. (Ärvd från Transaction) |
| PromoterType |
Identifierar unikt formatet för det |
| TransactionInformation |
Hämtar ytterligare information om en transaktion. (Ärvd från Transaction) |
Metoder
| Name | Description |
|---|---|
| Clone() |
Skapar en klon av transaktionen. (Ärvd från Transaction) |
| Complete() |
Försöker slutföra den beroende transaktionen. |
| DependentClone(DependentCloneOption) |
Skapar en beroende klon av transaktionen. (Ärvd från Transaction) |
| Dispose() |
Frigör de resurser som innehas av objektet. (Ärvd från Transaction) |
| EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions) |
Enlists a durable resource manager that supports two phase commit to participate in a transaction. (Ärvd från Transaction) |
| EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions) |
Enlists a durable resource manager that supports single phase commit optimization to participate in a transaction. (Ärvd från Transaction) |
| EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid) |
Enlists a resource manager that has an internal transaction using a promotable single phase enlistment (PSPE). (Ärvd från Transaction) |
| EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification) |
Enlists a resource manager that has an internal transaction using a promotable single phase enlistment (PSPE). (Ärvd från Transaction) |
| EnlistVolatile(IEnlistmentNotification, EnlistmentOptions) |
Enlists a volatile resource manager that supports two phase commit to participate in a transaction. (Ärvd från Transaction) |
| EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions) |
Enlists a volatile resource manager that supports single phase commit optimization to participate in a transaction. (Ärvd från Transaction) |
| Equals(Object) |
Avgör om den här transaktionen och det angivna objektet är lika. (Ärvd från Transaction) |
| GetHashCode() |
Returnerar hash-koden för den här instansen. (Ärvd från Transaction) |
| GetPromotedToken() |
Hämtar den |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions) |
Höjer upp och registrerar en beständig resurshanterare som stöder två faser för att delta i en transaktion. (Ärvd från Transaction) |
| Rollback() |
Återställer (avbryter) transaktionen. (Ärvd från Transaction) |
| Rollback(Exception) |
Återställer (avbryter) transaktionen. (Ärvd från Transaction) |
| SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid) |
Anger den distribuerade transaktionsidentifieraren som genereras av den icke-MSDTC-arrangören. (Ärvd från Transaction) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |
Händelser
| Name | Description |
|---|---|
| TransactionCompleted |
Anger att transaktionen har slutförts. (Ärvd från Transaction) |
Explicita gränssnittsimplementeringar
| Name | Description |
|---|---|
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
Hämtar en SerializationInfo med de data som krävs för att serialisera den här transaktionen. (Ärvd från Transaction) |
Gäller för
Trådsäkerhet
Den här typen är trådsäker.