Looking into it I verified that for example the value o "myInt" is not rolledback in the following scenario

int myInt = 10;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    myInt=20;
    Transaction t = Transaction.Current;

    t.Rollback();
}

So it got me thinking "Does a TransactionScope only rollback activities related to the database? Or there are other things that the Transaction can manage and I'm unware of those?"

有帮助吗?

解决方案

Current transaction affects only specific objects, that are called Resource Managers. Those object must implement specific interfaces to participate in transaction. ADO.NET SqlConnection object is an example. It is not difficult to create an object that works as "Transactional Memory". Those objects are called Volatile Resource Managers. A simple example is here.

其他提示

TransactionScope (and Transactions) are only used for handling database queries. It wouldn't really make sense to "rollback" changes that are only kept around temporarily anyway, (such as your int variable).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top