I've got a GUI form which is acting as the main thread, while I've got a different class for the actual work which is needed to be done.
Is there a way to properly check the CancellationPending
property of the worker since it's being activated from a different class, other than passing the worker as a parameter for the "DoJob" method so it could check the property?
The code (in the main class):
// This method is registered as the DoWork method for the worker
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
workClassInstance.DoJob();
}
private void buttonCancel_Click(object sender, RoutedEventArgs e)
{
if (bw.WorkerSupportsCancellation == true)
{
bw.CancelAsync();
}
}