internal void Close() { while (true) { this.CheckRegen(); if (!this.prioritizedQueue.Any()) { break; } Entry e = this.prioritizedQueue.Dequeue(); this.entries.Remove(e); e.Action(this); } foreach (Action action in this.lastQueue) { action(); } this.lastQueue.Clear(); foreach (KeyValuePair <int, Action <Transaction> > pair in this.postQueue) { Transaction parent = currentTransaction; try { if (pair.Key < 0) { currentTransaction = null; pair.Value(null); } else { Transaction transaction = new Transaction(); currentTransaction = transaction; try { pair.Value(transaction); } finally { transaction.Close(); } } } finally { currentTransaction = parent; } } this.postQueue.Clear(); }
internal void Close(bool usingLocal) { // ReSharper disable once ForCanBeConvertedToForeach for (int i = 0; i < this.sendQueue.Count; i++) { this.sendQueue[i](this); } this.sendQueue.Clear(); this.ReachedClose = true; this.CheckRegen(); while (true) { if (this.prioritizedQueue.Count < 1) { break; } Entry e = this.prioritizedQueue.Dequeue(); this.entries.Remove(e); e.Action(this); this.CheckRegen(); } // ReSharper disable once ForCanBeConvertedToForeach for (int i = 0; i < this.lastQueue.Count; i++) { this.lastQueue[i](); } this.lastQueue.Clear(); foreach (KeyValuePair <int, Action <Transaction> > pair in this.postQueue) { try { if (pair.Key < 0) { SetCurrentTransaction(null, usingLocal); pair.Value(null); } else { Transaction transaction = new Transaction(false); SetCurrentTransaction(transaction, usingLocal); try { pair.Value(transaction); } finally { transaction.Close(usingLocal); } } } finally { SetCurrentTransaction(this, usingLocal); } } this.postQueue.Clear(); }
internal void Close() { EnsureElevated(this); foreach (Node.Target target in this.TargetsToActivate) { target.IsActivated = true; } this.ActivatedTargets = true; // ReSharper disable once ForCanBeConvertedToForeach for (int i = 0; i < this.sendQueue.Count; i++) { this.sendQueue[i](this); } this.sendQueue.Clear(); while (this.prioritizedQueue.Count > 0 || this.sampleQueue.Count > 0) { while (this.prioritizedQueue.Count > 0) { this.CheckRegen(); Entry e = this.prioritizedQueue.Dequeue(); e.IsRemoved = true; e.Action(this); } List <Action> sq = this.sampleQueue; this.sampleQueue = new List <Action>(); foreach (Action s in sq) { s(); } } while (this.lastQueue.Count > 0) { this.lastQueue.Dequeue()(); } if (!this.hasParentTransaction) { void ExecuteInNewTransaction(Action <TransactionInternal> action, bool runStartHooks) { try { TransactionInternal transaction = new TransactionInternal(this.postQueue, this.splitQueue); if (!runStartHooks) { // this will ensure we don't run start hooks transaction.isElevated = true; } LocalTransaction.Value = transaction; try { action(transaction); } finally { transaction.Close(); } } finally { LocalTransaction.Value = this; } } while (this.postQueue.Count > 0 || this.splitQueue.Count > 0) { while (this.postQueue.Count > 0) { ExecuteInNewTransaction(this.postQueue.Dequeue(), true); } Dictionary <int, Action <TransactionInternal> > sq = this.splitQueue; this.splitQueue = new Dictionary <int, Action <TransactionInternal> >(); foreach (int n in sq.Keys.OrderBy(n => n)) { ExecuteInNewTransaction(sq[n], false); } } } }