Could be a thread migration problem?

 

From: [email protected]
[mailto:[email protected]] On Behalf Of Corey Kaylor
Sent: den 6 oktober 2009 23:32
To: [email protected]
Subject: [rhino-tools-dev] Re: Very strange System.Transactions-related bug

 

This is what we have used below in the past without any issues.

 

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]

      public class TransactionAttribute : ActionFilterAttribute

      {

            private readonly TimeSpan _timeout;

            private readonly IsolationLevel _isolationLevel;

            private TransactionScope _currentTransaction;

 

            public TransactionAttribute() :
this(IsolationLevel.Serializable)

            {

            }

 

            public TransactionAttribute(IsolationLevel isolationLevel) :
this(isolationLevel, TimeSpan.FromSeconds(30))

            {

            }

 

            public TransactionAttribute(IsolationLevel isolationLevel,
TimeSpan timeout)

            {

                  _isolationLevel = isolationLevel;

                  _timeout = timeout;

            }

 

            public override void OnActionExecuting(ActionExecutingContext
filterContext)

            {

                  var transactionOptions = new TransactionOptions
{IsolationLevel = _isolationLevel, Timeout = _timeout};

                  _currentTransaction = new
TransactionScope(TransactionScopeOption.Required, transactionOptions);

            }

 

            public override void OnActionExecuted(ActionExecutedContext
filterContext)

            {

                  using(_currentTransaction)

                  {

                        if(filterContext.Exception != null)

                              _currentTransaction.Complete();

                  }

            }

      }




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino Tools Dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rhino-tools-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to