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 在事务中登记的接口的资源管理器。 具体而言,事务管理器调用CommitRollback参与者的方法,具体取决于后者是否决定提交或回滚事务。 参与者应调用 Done 此对象的方法,让事务管理器知道它已完成其工作。
登记可以在准备阶段调用该方法之前随时调用DonePrepared该方法。 通过这样做,登记将投票为只读投票,这意味着它投票提交事务,但不需要收到最终结果。 请注意,调用该方法后 Done ,登记的参与者不会收到来自事务管理器的进一步通知。
方法
| 名称 | 说明 |
|---|---|
| Done() |
指示事务参与者已完成其工作。 |
| Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |
适用于
线程安全性
此类型是线程安全的。