Is there a way to neatly cancel a long-running background worker, say, after a timeout?
private void bw_DoWork(object sender, DoWorkEventArgs e)
{
ComplexRowContainer crc = (ComplexRowContainer)e.Argument;
string filename = crc.AppFullPath;
string calculatedChecksum = BuildChecksum(filename);
e.Result = calculatedChecksum;
}
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
string newChecksum = (string)e.Result;
if (newChecksum.Equals(oldChecksum))
{
MessageBox.Show("Same");
}
else
{
MessageBox.Show("Different");
}
}
And I do need to modify it for cancel events. However, is there anything 'built-in' that can automatically cancel a long-running task or should I build a timer to cancel on timeout? Thanks.