private async void CopyFileWithDelayButton_Click(object sender, EventArgs e) { ResetTokenSource(); CheckFileExists(); timer1.Enabled = true; listBox1.Items.Clear(); try { await FileOperations.CopyFileTask(_inputFileName, _outputFileName, numericTextBox1.AsInt, _cancellationTokenSource.Token); listBox1.Items.Add($"Done with {_currentLineNumber} processed"); listBox1.SelectedIndex = listBox1.Items.Count - 1; timer1.Enabled = false; } catch (OperationCanceledException oce) { timer1.Enabled = false; listBox1.Items.Add($"Operation cancelled with {_currentLineNumber} processed"); } catch (Exception ex) { listBox1.Items.Add(ex.Message); timer1.Enabled = false; } Text = "Code sample"; }
private async void CopyFileNoDelayButton_Click(object sender, EventArgs e) { ResetTokenSource(); CheckFileExists(); timer1.Enabled = true; listBox1.Items.Clear(); try { await FileOperations.CopyFileTask(_inputFileName, _outputFileName, 0, _cancellationTokenSource.Token); } catch (OperationCanceledException oce) { MessageBox.Show("Operation cancelled"); } catch (Exception ex) { MessageBox.Show(ex.Message); } listBox1.Items.Add("Done"); listBox1.SelectedIndex = listBox1.Items.Count - 1; timer1.Enabled = false; Text = "Code sample"; }