public bool JoinWifi(string ssidToJoin, Wlan.Dot11BssType bssType) { DoWorkEventArgs dwea = new DoWorkEventArgs(null); JoinWifi(ssidToJoin, bssType, null, dwea); IJcwTaskResult taskResult = dwea.Result as IJcwTaskResult; if (taskResult != null) { return(taskResult.Status == TaskResultStatus.Passed); } return(false); }
private void BackgroundWorkerThread_RunWorkerCompleted(object sender, EventArgs e) { // marshal form close call onto the thread where the control was created if (this.InvokeRequired) { this.Invoke(new EventHandler(BackgroundWorkerThread_RunWorkerCompleted), new object[] { sender, e }); return; } RunWorkerCompletedEventArgs ea = e as RunWorkerCompletedEventArgs; if (ea.Cancelled) { m_taskResult.Status = TaskResultStatus.Cancelled; } else if (ea.Error != null) { m_taskResult = ea.Result as IJcwTaskResult; m_taskResult.Text = ea.Error.Message + ea.Error.StackTrace; if (ea.Error.InnerException != null) { m_taskResult.Text += ea.Error.InnerException.Message + ea.Error.InnerException.StackTrace; } m_taskResult.Status = TaskResultStatus.Failed; } else { m_taskResult = ea.Result as IJcwTaskResult; } // The progress bar was dynamically added to the table layout panel's control // collection so need to call dispose on it or else we will have a memory leak. if (m_progressBar != null) { if (this.tableLayoutPanel1 != null && this.tableLayoutPanel1.Controls != null) { this.tableLayoutPanel1.Controls.Remove(m_progressBar); } m_progressBar.Dispose(); } m_task = null; this.Close(); }
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing) { if (m_progressBar != null) { if (this.tableLayoutPanel1 != null && this.tableLayoutPanel1.Controls != null) { this.tableLayoutPanel1.Controls.Remove(m_progressBar); } m_progressBar.Dispose(); } m_backgroundWorkerThread.DoWork -= BackgroundWorkerThread_DoWork; m_backgroundWorkerThread.ProgressChanged -= BackgroundWorkerThread_ProgressChanged; m_backgroundWorkerThread.RunWorkerCompleted -= BackgroundWorkerThread_RunWorkerCompleted; if (m_backgroundWorkerThread.IsBusy && !m_backgroundWorkerThread.CancellationPending) { m_backgroundWorkerThread.CancelAsync(); } m_backgroundWorkerThread.Dispose(); if (m_taskResult != null) { m_taskResult.Dispose(); m_taskResult = null; } if (components != null) { components.Dispose(); } } base.Dispose(disposing); }