private void Reschedule(VehicleStatusModel status) { if (!DateTime.TryParse(status.StatusDate, out var date)) { date = DateTime.UtcNow.AddSeconds(-8); // if the date is not valid then set the date to last 8 seconds, 8 seconds is for medium network latency } // maybe we need a better approach in real-world, because here waiting list is not processed any more and if no message is received vehicle // with specific vin then that vehicle will wait forever, this happens only when the queue can not be read lock (locker) { if (_waitingList.ContainsKey(status.VehicleId)) { _waitingList.Remove(status.VehicleId); CreateItem(status.VehicleId, date, status.VehicleStatus == 0 ? 60 : 75, AddToMappingList); // check it in the next 75 seconds, 15 second is for latency in the network } else { if (_mappingList.ContainsKey(status.VehicleId)) { var key = _mappingList[status.VehicleId]; if (JobQueue.ContainsKey(key)) { JobQueue.Remove(key); } } CreateItem(status.VehicleId, date, 75, AddToMappingList); } } }