1

我正面临下一个问题。我有一段代码是这样的:

DoSomething(){
  using (TransactionScope scope = new TransactionScope())
    {
      InsertSomething();
      InsertSomethingElse();
      InsertYetAnotherThing();
      ProcessDataRelatedWithThePreviousInserts();
      scope.Complete()
    }
}

在 ProcessDataRelatedWithThePreviousInserts 我检查一个条件,如果需要,工作流的其余部分被重定向到其他服务器中的消息队列。在另一台服务器中,我恢复消息,并继续工作流程(基本上,进行一些与 DoSomething 方法相关的其他插入)。

这是理论上的,因为我只有在 DoSomething 方法中删除 TransactionScope 时才能做到这一点。有没有办法完成我想做的事情,或者我需要改变交易的处理方式?

4

1 回答 1

0

你已经试过了吗

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    // ...
    using (TransactionScope innerscope = new TransactionScope(TransactionScopeOption.Supress)
    {
        ProcessDataRelatedWithThePreviousInserts();
    }
    scope.Complete();
}

显式禁止调用ProcessDataRelatedWithThePreviousInserts()的外部事务。

于 2010-02-24T17:13:42.570 回答