/// <summary> /// A method for disposing the modal. /// </summary> /// <returns>An instance of <see cref="Task"/>.</returns> public async Task DisposeAsync() { ModalModel = null; // Remove the instance of the model. await OnCloseAsync.Invoke(); // Invoke the on close method. OnSubmitAsync = null; // Remove the instance when submitting a modal. }
/// <summary> /// Closes connection to websocket server. /// </summary> /// <returns></returns> public async Task DisconnectAsync(WebSocketCloseStatus closeStatus = WebSocketCloseStatus.NormalClosure, string closeReason = "Normal closure.") { if (_webSocket.State != WebSocketState.Open) { throw new InvalidOperationException( $"WebSocket is not in open state. Current state: {_webSocket.State}"); } try { await _webSocket.CloseAsync(closeStatus, closeReason, _cancellationToken.Token); } catch (Exception exception) { await OnErrorAsync.Invoke(exception); } finally { _isConnected = false; _cancellationToken.Cancel(false); await OnCloseAsync.Invoke(closeReason); } }