public static DateTime AssureTimeMonotonicity(DateTime currentTime, IExtendedStorage storage, string storageKey) { using (var l = storage.AcquireLock(string.Format("{0}_lock", storageKey))) { var previousTime = default(DateTime); try { previousTime = storage.Retrieve<DateTime>(storageKey); } catch { } if (currentTime <= previousTime) { currentTime = previousTime.AddMilliseconds(1); } storage.StoreOrUpdate(storageKey, currentTime); } return currentTime; }