public bool Lock(string name) { lock (checksInProgress) { if (checksInProgress.ContainsKey(name)) { var check = checksInProgress[name]; var elapsed = DateTime.UtcNow - check.datetime; var task = check.task; if (task == null) { log.Warn("Previous check command execution in progress {0} for {1} milliseconds", name, elapsed.TotalMilliseconds); return(false); } log.Warn("Previous check command execution in progress {0} for {1} milliseconds, with current status: {2}", name, elapsed.TotalMilliseconds, task.Status); if (!task.IsCompleted) { return(false); } log.Warn("Task {0} was completed but not removed, so lock will be allowed.", name); } log.Debug("Locking {0}", name); checksInProgress[name] = new CheckData(); return(true); } }
public bool Lock(string name) { lock (checksInProgress) { if (checksInProgress.ContainsKey(name)) { var check = checksInProgress[name]; var elapsed = DateTime.UtcNow - check.datetime; var task = check.task; if (task == null) { log.Warn("Previous check command execution in progress {0} for {1} milliseconds", name, elapsed.TotalMilliseconds); return false; } log.Warn("Previous check command execution in progress {0} for {1} milliseconds, with current status: {2}", name, elapsed.TotalMilliseconds, task.Status); if ( ! task.IsCompleted) return false; log.Warn("Task {0} was completed but not removed, so lock will be allowed.", name); } log.Debug("Locking {0}", name); checksInProgress[name] = new CheckData(); return true; } }