protected override async Task <Lease <T> > AcquireLease() { var resource = leasables .Where(l => l.LeaseLastReleased + waitInterval < DateTimeOffset.UtcNow) .OrderBy(l => l.LeaseLastReleased) .FirstOrDefault(l => !workInProgress.ContainsKey(l)); if (resource == null) { return(null); } var lease = new Lease <T>(resource, defaultLeaseDuration); if (workInProgress.TryAdd(resource, lease)) { lease.NotifyGranted(); return(lease); } return(null); }