为什么事务不抛出TimeoutException?

时间:2011-02-25 19:53:20

标签: wcf transactions

1)在以下示例中,客户端TransactionScope TS1超时。但除非TS1调用Complete()并因此投票提交事务,否则不会抛出任何异常:

TimeSpan timeout = TimeSpan.FromSeconds(2);

using (TransactionScope scope1 = new TransactionScope(TransactionScopeOption.RequiresNew, timeout))
{
    proxy.GetAnimal(16); // returns after 10 seconds
    Thread.Sleep(6000);
}

我意识到如果不调用Complete(),事务就不会被提交,但我不明白为什么不管是否提交事务都不应该抛出超时异常?!

2)即使在事务超时后调用proxy.GetAnimal(),调用仍将成功:

    TimeSpan timeout = TimeSpan.FromSeconds(2);
    using (TransactionScope scope1 = new TransactionScope(TransactionScopeOption.RequiresNew, timeout)) 
    {
        proxy.GetAnimal(); // returns after 10 seconds
        Thread.Sleep(6000); 
        proxy.GetAnimal(); // shouldn't this call cause an exception?
    }

不会抛出异常更有意义吗?

1 个答案:

答案 0 :(得分:1)