Enlistment 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在交易的最後階段,協助登記的交易參與者與交易管理員之間的通訊。
public ref class Enlistment
public class Enlistment
type Enlistment = class
Public Class Enlistment
- 繼承
-
Enlistment
- 衍生
範例
下列範例示範 介面的 IEnlistmentNotification 實作,以及 Done 何時應該呼叫 方法。
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
備註
EnlistVolatile當叫用 物件的 和 EnlistDurable 方法 Transaction 來登記交易中的參與者時,它們會傳回描述登記的這個物件。
在交易認可的最後階段,交易管理員會將此物件傳遞至資源管理員,以 IEnlistmentNotification 實作已在交易中登記的介面。 具體來說,交易管理員會根據後者決定認可或復原交易,呼叫 Commit 參與者的 或 Rollback 方法。 參與者應該呼叫 Done 這個 物件的 方法,讓交易管理員知道它已完成其工作。
登記可以在準備階段中呼叫 方法之前 Prepared ,隨時呼叫 Done 方法。 如此一來,登記就會轉型唯讀投票,這表示它會在交易上投票認可,但不需要接收最終結果。 請注意,呼叫 方法之後 Done ,登記的參與者不會收到來自交易管理員的進一步通知。
方法
Done() |
指出交易參與者已完成其工作。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |
適用於
執行緒安全性
此型別具備執行緒安全。