Azavea.Open.Common.Chronometer.ReallyEndTiming C# (CSharp) Method

ReallyEndTiming() private static method

Behind the scenes we tack onto the key the name of the thread, in case multiple threads are running the same named operation at the same time.
private static ReallyEndTiming ( string originalKey, string keyWithThread ) : long
originalKey string The key provided by the client.
keyWithThread string Key consisting of the original key plus the thread name.
return long
        private static long ReallyEndTiming(string originalKey, string keyWithThread)
        {
            long duration = 0;
            bool durationValid = false;
            lock (_operationStartTimes)
            {
                if (_operationStartTimes.ContainsKey(keyWithThread))
                {
                    long startTime = _operationStartTimes[keyWithThread];
                    _operationStartTimes.Remove(keyWithThread);
                    duration = DateTime.Now.Ticks - startTime;
                    durationValid = true;
                } // else forget it, we can't time this one, oh well.
            }
            if (durationValid)
            {
                lock (_operationTotalTimes)
                {
                    if (_operationTotalTimes.ContainsKey(originalKey))
                    {
                        // Add the duration and increment the count.
                        _operationTotalTimes[originalKey].Add(duration);
                    }
                    else
                    {
                        // Not there yet, so just add the first values.
                        _operationTotalTimes[originalKey] = new List<long>(new long[]{duration});
                    }
                }
            }
            return durationValid ? duration : -1;
        }