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;
}