Consider downloading ProgressForm data. Your ProgressForm will become LoadDataForm, the task of which is to load data at startup, show the download progress to the operator and, possibly, give the operator the ability to cancel the download:
protected void OnButtonLoadData_Clicked(object sender, ...) { using (var loadDataForm = new loadDataForm()) { loadDataForm.LoadingParameters = myLoadingParameters; var dialogResult = loadDataForm.ShowDialog(this); if (dialogResult = DialogResult.Ok) { var loadedData = loadDataForm.LoadedData; ProcessData(loadedData); } } }
When loading a download data form, initialize the progress bar, run the task to load data and a timer to update the progress bar, or let the download task update the progress bar. When the download is complete, the data download task closes the dialog box.
If revocation is required: create a CancellationTokenSource, get a token from this source and pass the token as a parameter for the task. At the end of the event, cancel the cancelationTokenSource function and wait until the task is completed. Let the task regularly check the token if revocation is required.
Harald coppoolse
source share