如何:使用 SetAbort 和 SetComplete 方法

此示例说明了如何使用 System.EnterpriseServices.ContextUtil 类的静态 SetCompleteSetAbort 方法。有关这些方法的详细信息,请参阅自动事务中的投票

示例

'Try to do something crucial to the transaction in progress.
If Not DoSomeWork() Then
   ContextUtil.SetAbort()   'Something goes wrong.
Else
   ContextUtil.SetComplete()   'All goes well.
End If
//Try to do something crucial to the transaction in progress.
if( !DoSomeWork() )
{
   ContextUtil.SetAbort();   //Something goes wrong.
}
else
{
   ContextUtil.SetComplete();   //All goes well.
}

编译代码

此示例需要:

  • 引用 System 和 System.EnterpriseServices 命名空间。

请参见

概念

自动事务中的投票

Footer image

版权所有 (C) 2007 Microsoft Corporation。保留所有权利。