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

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

Sort of:

if(TransactionScope.Started|Enabled){...}
+3
source share
2 answers

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

An external transaction is a transaction in which your code is executed. can get a reference to the transaction environment by calling the static Current property of the Transaction class.

So, look at the transaction. Current .

+8
source

You can check the Transaction.Current property :

if(Transaction.Current != null)
{
    // running inside a transaction
}
+3
source

Source: https://habr.com/ru/post/1755178/


All Articles