Skip to content

Instantly share code, notes, and snippets.

@omerfarukz
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omerfarukz/8ed4df4e42c59b28d7eb to your computer and use it in GitHub Desktop.
Save omerfarukz/8ed4df4e42c59b28d7eb to your computer and use it in GitHub Desktop.
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");
}
}
}
}
@omerfarukz
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment