Timeout in nested converter

View code containing indirect nested transactions. I would like to know how timeouts are handled in nested transactions. Sample code

void RootMethod()
{   
   //default timeout is 60 seconds 
   using(TransactionScope scope = new TransactionScope())
   {
      /* Perform transactional work here */
      SomeMethod();
      scope.Complete();
   }
}

void SomeMethod()
{   
   //set timeout to 30 seconds
   TimeSpan timeout = TimeSpan.FromSeconds(30);
   using(TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, timeout))
   {
      /* Perform transactional work here */
      scope.Complete();
   }
}

      

MSDN states - In a nested TransactionScope hierarchy, a timeout is the concatenation of all timeouts. Essentially, the smallest timeout of all areas in the hierarchy takes precedence.

The first statement says the concatenation of all timeouts, but the second statement says it's the smallest of all the scopes. Am I correct in understanding that the above nested scoped code has a default timeout of 30 seconds and not 90?

+3


source to share


1 answer


It certainly won't be 90 seconds; it is a sum, not a union. Combining "now up to 30 seconds" and "not up to 60 seconds" is just "now up to 60 seconds". It is, of course, fairly easy to test by deliberately blocking yourself. i suspect means "intersection of all timeouts", in which case it has a value of 30 seconds; because: only the outermost transaction is allowed to commit, but any transaction in the hive can doom the entire transaction (a rollback at any level rolls back the entire remote transaction)



+2


source







All Articles