// Add a transaction to the table. Transactions are added to the end of the list in sorted order based on their // absolute timeout. internal int Add(InternalTransaction txNew) { // Tell the runtime that we are modifying global state. Thread.BeginCriticalRegion(); int readerIndex = 0; try { readerIndex = rwLock.AcquireReaderLock(); try { // Start the timer if needed before checking the current time since the current // time can be more efficient with a running timer. if (txNew.AbsoluteTimeout != long.MaxValue) { if (!this.timerEnabled) { if (!this.timer.Change(this.timerInterval, this.timerInterval)) { throw TransactionException.CreateInvalidOperationException( SR.GetString(SR.TraceSourceLtm), SR.GetString(SR.UnexpectedTimerFailure), null ); } this.lastTimerTime = DateTime.UtcNow.Ticks; this.timerEnabled = true; } } txNew.CreationTime = CurrentTime; AddIter(txNew); } finally { rwLock.ReleaseReaderLock(); } } finally { Thread.EndCriticalRegion(); } return(readerIndex); }