/// <summary> /// Closes the connection to the transport client instance. /// </summary> /// /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param> /// public override async Task CloseAsync(CancellationToken cancellationToken) { if (_closed) { return; } _closed = true; var clientId = GetHashCode().ToString(); var clientType = GetType(); try { //ServiceBusEventSource.Log.ClientCloseStart(clientType, EntityName, clientId); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); if (ManagementLink?.TryGetOpenedObject(out var _) == true) { cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); await ManagementLink.CloseAsync().ConfigureAwait(false); } ManagementLink?.Dispose(); ConnectionScope?.Dispose(); } catch (Exception) { _closed = false; //ServiceBusEventSource.Log.ClientCloseError(clientType, EntityName, clientId, ex.Message); throw; } finally { //ServiceBusEventSource.Log.ClientCloseComplete(clientType, EntityName, clientId); } }