Reputation: 22556
I have a windows form with a start and cancel button.
The start button does the following:
bootLoader = new BootLoader(this, _form1);
bootloader.Start();
Now when the user clicks the start button, the BootLoader class writes data to the COM port.
What I want to know is that how can I stop this operation from completeing when the user clicks the cancel button.
Currently I just have the following:
this.Close();
But It just closes the form and the data carries on being written to the com port.
Upvotes: 0
Views: 127
Reputation: 15055
Use a cancellable BackgroundWorker?
var bw = new BackgroundWorkder();
bw.WorkerSupportsCancellation = true;
Then in your DoWork
worker function you'll need to monitor the CancellationPending
flag which will become true after you call bw.CancelAsync()
.
Upvotes: 1