PreparingEnlistment.Prepared Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Geeft aan dat de transactie kan worden doorgevoerd.
public:
void Prepared();
public void Prepared();
member this.Prepared : unit -> unit
Public Sub Prepared ()
Voorbeelden
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
Opmerkingen
In de eerste fase (voorbereiding) van een doorvoer in twee fasen roept een resourcemanager die de Prepare methode van de IEnlistmentNotification interface implementeert, deze methode aan om aan te geven dat de transactie kan worden doorgevoerd.
Resource Manager kan de Done methode op elk gewenst moment aanroepen voordat deze methode wordt aangeroepen. Door dit te doen, is de opname een alleen-lezen stem, wat betekent dat het stemmen doorvoert op de transactie, maar niet het uiteindelijke resultaat hoeft te ontvangen.
Zodra deze methode wordt aangeroepen door een aanroep en voordat deze wordt geretourneerd, is het mogelijk dat een andere thread of dezelfde thread een aanroep kan maken in dezelfde oplijstingsmethode, zoals Rollback het uitvoeren van een terugdraaiactie. Dit kan leiden tot een impasse als de resourcebeheerimplementatie pas resourcevergrendelingen vrijgeeft nadat deze methode is geretourneerd.