public async Task Should_be_able_to_close_connection() { // first get a connection var connections = await managementClient.GetConnectionsAsync().ConfigureAwait(false); // then close it await managementClient.CloseConnectionAsync(connections.First()).ConfigureAwait(false); }
/// <summary> /// Closes the given connection /// </summary> /// <param name="source"></param> /// <param name="connection"></param> /// <param name="cancellationToken"></param> public static void CloseConnection( [NotNull] this IManagementClient source, [NotNull] Connection connection, CancellationToken cancellationToken = default ) { if (source == null) { throw new ArgumentNullException(nameof(source)); } source.CloseConnectionAsync(connection, cancellationToken) .GetAwaiter() .GetResult(); }
public static async Task KillAllConnectionsAsync( this IManagementClient client, CancellationToken cancellationToken ) { // We need this crunch with loop because it seems that management plugin has some delay in showing info // and we could receive an empty list of connections even if connections are open var wasClosed = false; do { var connections = await client.GetConnectionsAsync(cancellationToken).ConfigureAwait(false); foreach (var connection in connections) { await client.CloseConnectionAsync(connection, cancellationToken).ConfigureAwait(false); wasClosed = true; } await Task.Delay(500, cancellationToken).ConfigureAwait(false); } while (!wasClosed); }