views:

37

answers:

2

Is there a way to check if code is executed in a TransactionScope?

Something like:

if(TransactionScope.Started|Enabled){...}
+2  A: 

You could check the Transaction.Current property:

if(Transaction.Current != null)
{
    // running inside a transaction
}
Darin Dimitrov
+3  A: 

Hi,

yes there is way (directly copied from the MSDN documentation of TransactionScope):

The ambient transaction is the transaction your code executes in. You can obtain a reference to the ambient transaction by calling the static Current property of the Transaction class.

So have a look at Transaction.Current.

andyp