Transaction.EnlistVolatile Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Inscribe a un administrador de recursos volátil para participar en una transacción.
Sobrecargas
| Nombre | Description |
|---|---|
| EnlistVolatile(IEnlistmentNotification, EnlistmentOptions) |
Inscribe un administrador de recursos volátil que admite la confirmación en dos fases para participar en una transacción. |
| EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions) |
Inscribe un administrador de recursos volátil que admite la optimización de confirmación de fase única para participar en una transacción. |
Comentarios
Los administradores de recursos volátiles no pueden recuperarse de un error para completar una transacción en la que participaban.
EnlistVolatile(IEnlistmentNotification, EnlistmentOptions)
- Source:
- Transaction.cs
- Source:
- Transaction.cs
- Source:
- Transaction.cs
- Source:
- Transaction.cs
- Source:
- Transaction.cs
Inscribe un administrador de recursos volátil que admite la confirmación en dos fases para participar en una transacción.
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
Objeto que implementa la IEnlistmentNotification interfaz para recibir notificaciones de confirmación en dos fases.
- enlistmentOptions
- EnlistmentOptions
EnlistDuringPrepareRequired si el administrador de recursos quiere realizar trabajo adicional durante la fase de preparación.
Devoluciones
Objeto Enlistment que describe la inscripción.
Ejemplos
En el ejemplo siguiente se muestra una implementación de interfaz IEnlistmentNotification , así como la inclusión del objeto como participante en una transacción mediante el 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
Comentarios
Los administradores de recursos volátiles no pueden recuperarse de un error para completar una transacción en la que participaban. Para obtener una inscripción duradera en una transacción, use el EnlistDurable método .
Los administradores de recursos inscritos para participar en una transacción a través de este método reciben notificaciones de confirmación en dos fases que corresponden a los métodos definidos en la IEnlistmentNotification interfaz.
Se aplica a
EnlistVolatile(ISinglePhaseNotification, EnlistmentOptions)
- Source:
- Transaction.cs
- Source:
- Transaction.cs
- Source:
- Transaction.cs
- Source:
- Transaction.cs
- Source:
- Transaction.cs
Inscribe un administrador de recursos volátil que admite la optimización de confirmación de fase única para participar en una transacción.
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
Objeto que implementa la ISinglePhaseNotification interfaz que debe poder recibir la confirmación de una sola fase y dos notificaciones de confirmación de fase.
- enlistmentOptions
- EnlistmentOptions
EnlistDuringPrepareRequired si el administrador de recursos quiere realizar trabajo adicional durante la fase de preparación.
Devoluciones
Objeto Enlistment que describe la inscripción.
Comentarios
Los administradores de recursos volátiles no pueden recuperarse de un error para completar una transacción en la que participaban. Para obtener una inscripción duradera en una transacción, use el EnlistDurable método .
Debe tener en cuenta que, incluso cuando la implementación de Resource Manager se inscribe con este método, no se garantiza que reciba una confirmación de una sola fase. En su lugar, el administrador de transacciones puede enviar notificaciones de confirmación en dos fases.