void frmManagePostCodes_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e) { try { if (worker != null) { if (worker.IsBusy) { if (DialogResult.No == MessageBox.Show("Coordinates are not fully updated! " + Environment.NewLine + "Do you still want to close this form ?", "Update Coordinates", MessageBoxButtons.YesNo)) { e.Cancel = true; return; } } IsFormClosed = true; worker.CancelAsync(); worker.Dispose(); worker = null; } if (UpdateCurrentworker != null) { if (UpdateCurrentworker.IsBusy) { if (DialogResult.No == MessageBox.Show("Coordinates are not fully updated! " + Environment.NewLine + "Do you still want to close this form ?", "Update Coordinates", MessageBoxButtons.YesNo)) { e.Cancel = true; return; } } IsFormClosed = true; UpdateCurrentworker.CancelAsync(); UpdateCurrentworker.Dispose(); UpdateCurrentworker = null; } } catch { } }
void UpdateCurrent_Click(object sender, EventArgs e) { try { if (DialogResult.Yes == MessageBox.Show("Do you want to update coordinates ? " + Environment.NewLine + "This will take a few minutes to update", "Update Coordinates", MessageBoxButtons.YesNo)) { InitializeCurrentUpdateWorker(); btnUpdateCoordinates.Enabled = false; grdSelectedPostCodes.Enabled = false; btnSaveClose.Enabled = false; btnExit1.Enabled = false; lblUpdate.Text = string.Empty; UpdateCurrentworker.RunWorkerAsync(); } } catch (Exception ex) { ENUtils.ShowMessage(ex.Message); } }