开发者

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

Is there 开发者_开发问答a way to check if code is executed in a TransactionScope?

Something like:

if(TransactionScope.Started|Enabled){...}


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.


You could check the Transaction.Current property:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜