4
votes

Found this line in an application I just took over, and it doesn't make much sense.

using (new TransactionScope(TransactionScopeOption.Suppress, new TimeSpan(1,0,0))) {

This occurs immediately inside a nservicebus message handler method and covers the entire handler.

It appears to be trying to suppress the ambient transaction and after an hour aborting. What happens when the timeout expires? I assume this is just a combination of options that doesn't mean anything reasonable. But what does it result in happening?

1

1 Answers

0
votes

Suppress means that the ambient transaction is not used; and that, in affect, the operations within the scope are not performed in a transaction. This allows you to execute operations outside of the current transaction without being affected by that transaction. e.g.:

using(var trans = new TransactionScope())
{
   // do operations within transaction
   using(var unscoped = new TransactionScope(TransactionScopeOption.Suppress))
   {
      // do "immediate" operations
   }
   // do operations within transaction
   // NOTE: No trans.Complete() called
}

// operations performed within "scoped" are not rolled back.

I'm not really sure if the timeout really makes any sense with Suppress