DependentTransaction Třída
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Popisuje klon transakce poskytující záruku, že transakce nelze potvrdit, dokud aplikace nepřijde na zbytek práce na transakci. Tuto třídu nelze zdědit.
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
- Dědičnost
- Atributy
Příklady
Následující příklad ukazuje, jak vytvořit závislá transakce.
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
Poznámky
Jedná se DependentTransaction o klon objektu Transaction vytvořeného DependentClone pomocí metody. Jejím jediným účelem je umožnit aplikaci odpočinek a zaručit, že transakce nemůže potvrdit, zatímco práce se stále provádí na transakci (například v pracovním vlákně).
Po dokončení práce v rámci klonované transakce je konečně dokončena a připravena k potvrzení, může informovat tvůrce transakce pomocí Complete metody. Můžete tak zachovat konzistenci a správnost dat.
Výčet DependentCloneOption slouží k určení chování při potvrzení. Toto řízení chování umožňuje, aby aplikace přišla do klidu, a také poskytuje podporu souběžnosti.
Vlastnosti
| Name | Description |
|---|---|
| IsolationLevel |
Získá úroveň izolace transakce. (Zděděno od Transaction) |
| PromoterType |
Jednoznačně identifikuje formát |
| TransactionInformation |
Načte další informace o transakci. (Zděděno od Transaction) |
Metody
| Name | Description |
|---|---|
| Clone() |
Vytvoří klon transakce. (Zděděno od Transaction) |
| Complete() |
Pokusí se dokončit závislé transakce. |
| DependentClone(DependentCloneOption) |
Vytvoří závislý klon transakce. (Zděděno od Transaction) |
| Dispose() |
Uvolní prostředky, které objekt uchovává. (Zděděno od Transaction) |
| EnlistDurable(Guid, IEnlistmentNotification, EnlistmentOptions) |
Zapíše trvalý správce prostředků, který podporuje dvoufázové potvrzení účasti v transakci. (Zděděno od Transaction) |
| EnlistDurable(Guid, ISinglePhaseNotification, EnlistmentOptions) |
Zapíše trvalý správce prostředků, který podporuje optimalizaci potvrzení jedné fáze pro účast v transakci. (Zděděno od Transaction) |
| EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification, Guid) |
Zařadí správce prostředků, který má interní transakci pomocí propagační jednofázové zařazení (PSPE). (Zděděno od Transaction) |
| EnlistPromotableSinglePhase(IPromotableSinglePhaseNotification) |
Zařadí správce prostředků, který má interní transakci pomocí propagační jednofázové zařazení (PSPE). (Zděděno od Transaction) |
| EnlistVolatile(IEnlistmentNotification, EnlistmentOptions) |
Zapsá těkavý správce prostředků, který podporuje dvoufázové potvrzení účasti v transakci. (Zděděno od Transaction) |
| EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions) |
Zapíše nestálý správce prostředků, který podporuje optimalizaci potvrzení jedné fáze, aby se účastnila transakce. (Zděděno od Transaction) |
| Equals(Object) |
Určuje, zda tato transakce a zadaný objekt jsou rovny. (Zděděno od Transaction) |
| GetHashCode() |
Vrátí kód hash pro tuto instanci. (Zděděno od Transaction) |
| GetPromotedToken() |
|
| GetType() |
Získá Type aktuální instance. (Zděděno od Object) |
| MemberwiseClone() |
Vytvoří mělkou kopii aktuálního Object. (Zděděno od Object) |
| PromoteAndEnlistDurable(Guid, IPromotableSinglePhaseNotification, ISinglePhaseNotification, EnlistmentOptions) |
Podporuje a zapíše trvalý správce prostředků, který podporuje dvoufázové potvrzení účasti v transakci. (Zděděno od Transaction) |
| Rollback() |
Vrátí zpět (přerušení) transakce. (Zděděno od Transaction) |
| Rollback(Exception) |
Vrátí zpět (přerušení) transakce. (Zděděno od Transaction) |
| SetDistributedTransactionIdentifier(IPromotableSinglePhaseNotification, Guid) |
Nastaví identifikátor distribuovaných transakcí vygenerovaný propagátorem bez MSDTC. (Zděděno od Transaction) |
| ToString() |
Vrátí řetězec, který představuje aktuální objekt. (Zděděno od Object) |
Událost
| Name | Description |
|---|---|
| TransactionCompleted |
Označuje, že transakce je dokončena. (Zděděno od Transaction) |
Explicitní implementace rozhraní
| Name | Description |
|---|---|
| ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
SerializationInfo Získá s daty potřebnými k serializaci této transakce. (Zděděno od Transaction) |
Platí pro
Bezpečný přístup z více vláken
Tento typ je bezpečný pro přístup z více vláken.