private void btConnect_Click(object sender, EventArgs e) { if (_busy) { return; } if (_ftp != null) { _ftp.Disconnect(); _ftp.Dispose(); _ftp = null; SetConnectedState(false); return; } ConnectForm dlg = new ConnectForm(); if (dlg.ShowDialog() == DialogResult.OK) { _ftp = new Ftp(); _ftp.LogWriter = new RichTextBoxLogger(tbxLog, tbxLog.MaxLength, LogLevel.Info); // set event handlers _ftp.StateChanged += OnStateChanged; _ftp.Scanning += OnScanning; _ftp.TransferProgressChanged += OnTransferProgress; _ftp.DeleteProgressChanged += OnDeleteProgress; _ftp.FileTransferIssue += OnFileTransferIssue; try { _ftp.BeginConnect(dlg.Server, dlg.Port, dlg.SslMode, OnConnectFinish, dlg); } catch (Exception ex) { Log(ex); SetConnectedState(false); } } }