private async void ImportBtn_Click(object sender, EventArgs e)
{
// List of files to process
List<SnapshotFile> Files = new List<SnapshotFile>();
foreach (ListViewItem I in SnapshotView.Items)
{
if (I.Checked)
Files.Add(I.Tag as SnapshotFile);
}
// Make sure we have a snapshot selected
if (Files.Count == 0)
{
MessageBox.Show("You must select at least 1 snapshot to process.", "Error");
return;
}
// Disable this form, and show the TaskForm
this.Enabled = false;
TaskForm.Show(this, "Importing Snapshots", "Importing Snapshots", true, ProgressBarStyle.Continuous, Files.Count);
TaskForm.Cancelled += (s, ev) =>
{
TaskForm.Progress.Report(new TaskProgressUpdate("Cancelling...."));
ImportTaskSource.Cancel();
};
// Setup cancellation
ImportTaskSource = new CancellationTokenSource();
CancellationToken CancelToken = ImportTaskSource.Token;
// Wrap in a Task so we dont lock the GUI
await Task.Run(() => ImportSnaphotFiles(Files, CancelToken), CancelToken);
// Update the snapshots found close task form
BuildList();
TaskForm.CloseForm();
this.Enabled = true;
this.Focus();
}