有没有办法巧妙地取消一个长时间运行的后台工作人员,比如说,在超时后?
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");
}
}
我确实需要为取消事件修改它。但是,是否有任何“内置”可以自动取消长时间运行的任务,或者我应该建立一个计时器以在超时时取消?谢谢。