Ejemplo n.º 1
0
 public Scope(TransactionScope instance, bool ownsInstance)
 {
     if (instance == null)
         throw new ArgumentNullException("instance");
     _instance = instance;
     _ownsInstance = ownsInstance;
     Thread.BeginThreadAffinity();
     _parent = _head;
     // If this is the Start of the outermost Scope, set SingleConnection to true.
     if (_head == null) {
         SingleConnection = true;
         ConnectionString = "";
         connection = null;
         LastTransactionSuccess = true;
         Error = "";
     }
     _head = this;
 }
Ejemplo n.º 2
0
 public void Dispose()
 {
     if (!_disposed) {
         _disposed = true;
         Debug.Assert(this == _head, "Disposed out of order.");
         _head = _parent;
         Thread.EndThreadAffinity();
         if (_ownsInstance) {
             IDisposable disposable = _instance as IDisposable;
             if (disposable != null) {
                 try {
                     disposable.Dispose();
                 }
                 catch (Exception ex) {
                     // If the outer scope commit, but not the inner one, then  the whole transaction will be aborted by throwing a TransactionAbortedException
                     // as soon as the outer Scope goes out of scope. So although this is a legitimate exception, we just eat it.
                     LastTransactionSuccess = false;
                     Error = ex.Message;
                 }
             }
         }
         if (_head == null) {
             // Meaning that this is the outermost scope
             if (connection != null)
                 connection.Dispose();
         }
     }
 }