开发者

Why doesn’t transaction throw a TimeoutException?

开发者 https://www.devze.com 2023-02-13 06:46 出处:网络
1) In the following example client-side TransactionScope TS1 timeouts. But unless TS1 calls Complete() and thus votes to commit the transaction, no exception is thrown:

1) In the following example client-side TransactionScope TS1 timeouts. But unless TS1 calls Complete() and thus votes to commit the transaction, no exception is thrown:

TimeSpan timeout = TimeSpan.FromSeconds(2);

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

I realize that without calling Complete() the transaction won’t get committed, but I fail to see why timeout exception shouldn’t be thrown regardless of whether transaction is committed or not?!

2) Even if proxy.GetAnimal() is called after the transaction timeout, the call will still succeed:

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

Wouldn't throwing an exception made more sense?


See TransactionScope and Timeout Issue

0

精彩评论

暂无评论...
验证码 换一张
取 消