Enlistment Classe
Definizione
Facilita la comunicazione tra un partecipante alla transazione integrato e la gestione transazioni durante la fase finale della transazione.Facilitates communication between an enlisted transaction participant and the transaction manager during the final phase of the transaction.
public ref class Enlistment
public class Enlistment
type Enlistment = class
Public Class Enlistment
- Ereditarietà
-
Enlistment
- Derivato
Esempio
Nell'esempio seguente viene illustrata un'implementazione dell' IEnlistmentNotification interfaccia e quando il Done metodo deve essere chiamato.The following example shows an implementation of the IEnlistmentNotification interface, and when the Done method should be called.
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 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
Commenti
Quando EnlistVolatile EnlistDurable Transaction vengono richiamati i metodi e dell'oggetto per integrare un partecipante a una transazione, viene restituito questo oggetto che descrive l'integrazione.When the EnlistVolatile and EnlistDurable methods of the Transaction object are invoked to enlist a participant in a transaction, they return this object describing the enlistment.
Durante la fase finale del commit della transazione, la gestione transazioni passa questo oggetto a un gestore di risorse che implementa l' IEnlistmentNotification interfaccia integrata in una transazione.During the final phase of the transaction commit, the transaction manager passes this object to a resource manager implementing the IEnlistmentNotification interface that has enlisted in a transaction. In particolare, la gestione transazioni chiama il Commit metodo o Rollback del partecipante, a seconda del fatto che quest'ultimo abbia deciso di eseguire il commit o il rollback della transazione.Specifically, the transaction manager calls either the Commit or the Rollback method of the participant, depending on whether the latter has decided to commit or roll back the transaction. Il partecipante deve chiamare il Done metodo di questo oggetto per comunicare al gestore delle transazioni che ha completato il lavoro.The participant should call the Done method of this object to let the transaction manager know that it has completed its work.
Un elenco può chiamare il Done metodo in qualsiasi momento prima che venga chiamato Prepared nella fase di preparazione.An enlistment can call the Done method at anytime before it has called Prepared in the prepare phase. In questo modo, l'integrazione esegue il cast di un voto di sola lettura, vale a dire che vota il commit sulla transazione, ma non deve ricevere il risultato finale.By doing so, the enlistment is casting a read only vote, meaning that it votes commit on the transaction but does not need to receive the final outcome. Si noti che, dopo la Done chiamata del metodo, il partecipante integrato non riceve altre notifiche dalla gestione transazioni.Note that, after the Done method is called, the enlisted participant receives no further notifications from the transaction manager.
Metodi
Done() |
Indica che il partecipante alla transazione ha completato le relative operazioni.Indicates that the transaction participant has completed its work. |
Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object. (Ereditato da Object) |
GetHashCode() |
Funge da funzione hash predefinita.Serves as the default hash function. (Ereditato da Object) |
GetType() |
Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance. (Ereditato da Object) |
MemberwiseClone() |
Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object. (Ereditato da Object) |
ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object. (Ereditato da Object) |
Si applica a
Thread safety
Questo tipo è thread-safe.This type is thread safe.