protected override async Task ReleaseLease(Lease <T> lease) { using (var connection = new SqlConnection(database.ConnectionString)) { await connection.OpenAsync(); var cmd = connection.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = @"Alluvial.ReleaseLease"; cmd.Parameters.AddWithValue(@"@resourceName", lease.ResourceName); cmd.Parameters.AddWithValue(@"@token", (int)lease.OwnerToken); try { var leaseLastReleased = (DateTimeOffset)await cmd.ExecuteScalarAsync(); lease.NotifyReleased(leaseLastReleased); Debug.WriteLine("[Distribute] ReleaseLease: " + lease); } catch (Exception ex) { Debug.WriteLine("[Distribute] ReleaseLease (failed): " + lease + "\n" + ex); } } }
protected override async Task ReleaseLease(Lease <T> lease) { if (!workInProgress.Values.Any(l => l.GetHashCode().Equals(lease.GetHashCode()))) { Debug.WriteLine("[Distribute] ReleaseLease (failed): " + lease); return; } Lease <T> _; if (workInProgress.TryRemove(lease.Leasable, out _)) { lease.NotifyReleased(); Debug.WriteLine("[Distribute] ReleaseLease: " + lease); } lease.NotifyCompleted(); }