Transaction.EnlistVolatile Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Recorre a um gestor de recursos volátil para participar numa transação.
Sobrecargas
| Name | Description |
|---|---|
| EnlistVolatile(IEnlistmentNotification, EnlistmentOptions) |
Utiliza um gestor de recursos volátil que suporta compromisso em duas fases para participar numa transação. |
| EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions) |
Utiliza um gestor de recursos voláteis que suporta otimização de compromissos de fase única para participar numa transação. |
Observações
Gestores de recursos voláteis não conseguem recuperar da falha em completar uma transação em que estavam a participar. Para mais informações sobre recursos voláteis e duradouros, bem como sobre como recrutar um recurso, veja Implementar uma Resource Manager. Para mais informações sobre como um gestor de recursos responde à notificação de commit e prepara o commit, consulte Committing A Transaction In Single-Phase and Multi-Phase.
EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)
- Origem:
- Transaction.cs
- Origem:
- Transaction.cs
- Origem:
- Transaction.cs
- Origem:
- Transaction.cs
- Origem:
- Transaction.cs
Utiliza um gestor de recursos volátil que suporta compromisso em duas fases para participar numa transação.
public:
System::Transactions::Enlistment ^ EnlistVolatile(System::Transactions::IEnlistmentNotification ^ enlistmentNotification, System::Transactions::EnlistmentOptions enlistmentOptions);
public System.Transactions.Enlistment EnlistVolatile(System.Transactions.IEnlistmentNotification enlistmentNotification, System.Transactions.EnlistmentOptions enlistmentOptions);
member this.EnlistVolatile : System.Transactions.IEnlistmentNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
Public Function EnlistVolatile (enlistmentNotification As IEnlistmentNotification, enlistmentOptions As EnlistmentOptions) As Enlistment
Parâmetros
- enlistmentNotification
- IEnlistmentNotification
Um objeto que implementa a IEnlistmentNotification interface para receber notificações de commit em duas fases.
- enlistmentOptions
- EnlistmentOptions
EnlistDuringPrepareRequired Se o gestor de recursos quiser realizar trabalho adicional durante a fase de preparação.
Devoluções
Um Enlistment objeto que descreve o alistamento.
Exemplos
O exemplo seguinte mostra uma implementação de IEnlistmentNotification interface, bem como a participação do objeto numa transação usando o EnlistVolatile método.
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
Observações
Gestores de recursos voláteis não conseguem recuperar da falha em completar uma transação em que estavam a participar. Para obter um alistamento duradouro numa transação, utilize o EnlistDurable método.
Os gestores de recursos recrutados para participar numa transação através deste método recebem notificações de commit em duas fases que correspondem aos métodos definidos na IEnlistmentNotification interface.
Aplica-se a
EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)
- Origem:
- Transaction.cs
- Origem:
- Transaction.cs
- Origem:
- Transaction.cs
- Origem:
- Transaction.cs
- Origem:
- Transaction.cs
Utiliza um gestor de recursos voláteis que suporta otimização de compromissos de fase única para participar numa transação.
public:
System::Transactions::Enlistment ^ EnlistVolatile(System::Transactions::ISinglePhaseNotification ^ singlePhaseNotification, System::Transactions::EnlistmentOptions enlistmentOptions);
public System.Transactions.Enlistment EnlistVolatile(System.Transactions.ISinglePhaseNotification singlePhaseNotification, System.Transactions.EnlistmentOptions enlistmentOptions);
member this.EnlistVolatile : System.Transactions.ISinglePhaseNotification * System.Transactions.EnlistmentOptions -> System.Transactions.Enlistment
Public Function EnlistVolatile (singlePhaseNotification As ISinglePhaseNotification, enlistmentOptions As EnlistmentOptions) As Enlistment
Parâmetros
- singlePhaseNotification
- ISinglePhaseNotification
Um objeto que implementa a ISinglePhaseNotification interface e que deve ser capaz de receber notificações de commit de fase única e de duas fases.
- enlistmentOptions
- EnlistmentOptions
EnlistDuringPrepareRequired Se o gestor de recursos quiser realizar trabalho adicional durante a fase de preparação.
Devoluções
Um Enlistment objeto que descreve o alistamento.
Observações
Gestores de recursos voláteis não conseguem recuperar da falha em completar uma transação em que estavam a participar. Para obter um alistamento duradouro numa transação, utilize o EnlistDurable método. Para mais informações sobre recursos voláteis e duradouros, bem como sobre como recrutar um recurso, veja Implementar uma Resource Manager. Para mais informações sobre como um gestor de recursos responde à notificação de commit e prepara o commit, consulte Committing A Transaction In Single-Phase and Multi-Phase.
Deves notar que, mesmo quando a implementação do gestor de recursos se inscreve neste método, não é garantido que receba um commit de fase única. O gestor de transações ainda pode enviar notificações de commit em duas fases. Para mais informações sobre a otimização de commit de fase única, consulte Otimização Usando Commit de Fase Única e Notificação de Fase Única Promotível.