private void btnChangeDb_Click(object sender, EventArgs e) { frmConnectionRepository frm = new frmConnectionRepository(); if (frm.ShowDialog() != DialogResult.OK) { return; } ConnectionParams cp = frm.SelectedDataSource; if (cp == null) return; string error = String.Empty; AsyncConnectionResult cResult = frmAsyncConnectionOpener.TryToOpenConnection(cp, ref error); if (cResult == AsyncConnectionResult.Error) { MessageBox.Show(error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (cResult != AsyncConnectionResult.Success) return; _connParams = cp; Caption = _connParams.InfoDbServer; }
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { try { if (e.Cancelled) { _result = AsyncConnectionResult.Cancel; DialogResult = DialogResult.Cancel; return; } if (e.Error != null) { _lastError = e.Error.Message; _result = AsyncConnectionResult.Error; DialogResult = DialogResult.Abort; return; } _result = AsyncConnectionResult.Success; DialogResult = DialogResult.OK; } finally { _connecting = false; } }
private bool AsyncTestConnection(bool showErrorDialog) { bool result = false; ConnectionParams cConn = GetCurrentConnectionSpec(); cConn.TimeOut = "15"; string error = String.Empty; AsyncConnectionResult aResult = frmAsyncConnectionOpener.TryToOpenConnection(cConn, ref error); if (aResult == AsyncConnectionResult.Success) { result = true; } else if (aResult == AsyncConnectionResult.Error) { if (showErrorDialog) { MessageBox.Show(error, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { throw new Exception(error); } } return(result); }
/// <summary> /// Used to handle if the connection was successful or not if the ConnectAsync method. /// </summary> /// <param name="connected">If the connection was successful or not.</param> /// <param name="ex">If the connection was not successful, this will not be null</param> private void OnConnect(bool connected, Exception ex) { checkDisposed(); //If the connection is successful, start reading data. if (connected) { beginRead(); } //Call the event. AsyncConnectionResult?.Invoke(this, new TcpSocketConnectionStateEventArgs(connected, ex)); }
private void btnCancel_Click(object sender, EventArgs e) { if (_cancelled) { return; } bw.CancelAsync(); _cancelled = true; _result = AsyncConnectionResult.Cancel; DialogResult = DialogResult.Cancel; }