Last active
August 29, 2015 14:04
-
-
Save omerfarukz/8ed4df4e42c59b28d7eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Transactions; | |
namespace TransactionInterceptorSample | |
{ | |
class MainClass | |
{ | |
public static void Main(string[] args) | |
{ | |
DoItOne(0); | |
using (var trn = new TransactionScope()) | |
{ | |
Transaction.Current.TransactionCompleted += (o, e) => | |
{ | |
Console.WriteLine("transaction complated"); | |
}; | |
DoItOne(0); | |
DoItOne(1); | |
trn.Complete(); | |
} | |
DoItOne(0); | |
Console.ReadKey(); | |
} | |
static void DoItOne(int i) | |
{ | |
if (Transaction.Current != null) | |
{ | |
if (i == 1) | |
Transaction.Current.Rollback(); | |
Console.WriteLine("transaction is detected:" + Transaction.Current.TransactionInformation.Status); | |
} | |
else | |
{ | |
Console.WriteLine("there is no transaction in this scope"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output:
there is no transaction in this scope
transaction is detected:Active
transaction complated
transaction is detected:Aborted
transaction complated
there is no transaction in this scope