/// <summary> /// Button that begin the validation of the entered URL. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonVerify_Click(object sender, EventArgs e) { ErrorProviderTimeCorrection.SetError(ComboBoxUrlTimeCorrection, string.Empty); //Clears input errors. if (!ComboBoxUrlTimeCorrection.Text.StartsWith("http")) { ErrorProviderTimeCorrection.SetError(ComboBoxUrlTimeCorrection, Localization.Strings.TcUrlMustContainHttp); //Verifies if the URL is valid. } if (!ComboBoxUrlTimeCorrection.Text.Contains("://")) { ErrorProviderTimeCorrection.SetError(ComboBoxUrlTimeCorrection, Localization.Strings.TcUrlInvalid); //Verifies if the URL is valid. } if (_plugin.TimeCorrections[ComboBoxUrlTimeCorrection.Text] != null) { ErrorProviderTimeCorrection.SetError(ComboBoxUrlTimeCorrection, Localization.Strings.TcUrlExists); //Verifies if the URL is existing. } if (ErrorProviderTimeCorrection.GetError(ComboBoxUrlTimeCorrection) != string.Empty) { return; //Prevents the validation if input has an error. } PictureBoxTimeCorrection.Image = ImageListErrorProvider.Images[1]; //Displays working icon. LabelStatusTimeCorrection.Text = Localization.Strings.TcPleaseWaitVerifying; //Diplays attempt message. ButtonVerify.Enabled = false; //Prevents the user to retry the URL validation. ComboBoxUrlTimeCorrection.Enabled = false; //Prevents the user to modify the URL. WorkerWaitForCheck.RunWorkerAsync(); //Starts the worker that handles the thread that handles the validation attempt. }
/// <summary> /// Windows Form Closing. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FormTimeCorrection_FormClosing(object sender, FormClosingEventArgs e) { if (WorkerWaitForCheck.IsBusy) //Checks if the worker is busy. { ButtonCancel.Enabled = false; //Disables the cancel button to prevent multiple cancels. WorkerWaitForCheck.CancelAsync(); //Asks the worker to cancel the thread. e.Cancel = true; //Prevents the form from closing just yet. } }