Enlistment Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Facilite la communication entre un participant de transaction inscrit et le gestionnaire de transactions pendant la phase finale de la transaction.
public ref class Enlistment
public class Enlistment
type Enlistment = class
Public Class Enlistment
- Héritage
-
Enlistment
- Dérivé
Exemples
L’exemple suivant montre une implémentation de l’interface IEnlistmentNotification et quand la Done méthode doit être appelée.
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
Remarques
Lorsque les méthodes et EnlistVolatile les EnlistDurable méthodes de l’objet Transaction sont appelées pour inscrire un participant dans une transaction, ils retournent cet objet décrivant l’inscription.
Pendant la dernière phase de la validation de transaction, le gestionnaire de transactions transmet cet objet à un gestionnaire de ressources implémentant l’interface IEnlistmentNotification inscrite dans une transaction. Plus précisément, le gestionnaire de transactions appelle la ou la CommitRollback méthode du participant, selon que celui-ci a décidé de valider ou de restaurer la transaction. Le participant doit appeler la Done méthode de cet objet pour informer le gestionnaire de transactions qu’il a terminé son travail.
Une inscription peut appeler la Done méthode à tout moment avant d’avoir appelé Prepared dans la phase de préparation. En procédant ainsi, l’inscription porte un vote en lecture seule, ce qui signifie qu’il vote sur la transaction, mais n’a pas besoin de recevoir le résultat final. Notez que, une fois la Done méthode appelée, le participant inscrit ne reçoit aucune autre notification du gestionnaire de transactions.
Méthodes
| Nom | Description |
|---|---|
| Done() |
Indique que le participant à la transaction a terminé son travail. |
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |
S’applique à
Cohérence de thread
Ce type est thread safe.