using System.Transactions; ... using (TransactionScope scope = new TransactionScope()) { // Perform transactional work here. Transaction currentTransaction = Transaction.Current; TransactionManager.AddTransaction(currentTransaction); scope.Complete(); }
using System.Transactions; ... using (TransactionScope scope = new TransactionScope()) { // Perform transactional work here. Transaction currentTransaction = Transaction.Current; TransactionManager.AddTransaction(currentTransaction); // Explicitly abort the transaction. TransactionManager.DistributedTransactionStarted += delegate(object sender, EventArgs e) { currentTransaction.Rollback(); }; scope.Complete(); }This code initializes a new TransactionScope object to perform transactional work, adds the transaction to the TransactionManager using the AddTransaction method, and explicitly aborts the transaction by rolling it back using the DistributedTransactionStarted event. Package Library: System.Transactions is a built-in .NET package library that provides transactional support for distributed applications.