You can't force the termination of a background worker, it simply isn't designed for that.
You have 3 options, in the order in which I would use them.
1) If you use .NET 4.0 you can use the TPL, Sacha Barber has written a series of articles on the subject.
Task Parallel Library: 1 of n[
^]
2) You can use the good old System.Threading.Thread
Threading Tutorial (X#)[
^]
3) You can get the get the Thread the BackgroundWorker is running on in the DoWork event save it in a field and you can then abort the thread.
private Thread _backgroundWorkerThread;
public void StartBackgroundWorker()
{
BackgroundWorker backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += DoWork;
backgroundWorker.RunWorkerAsync();
}
public void AbortBackgroundWorker()
{
if(_backgroundWorkerThread != null)
_backgroundWorkerThread.Abort();
}
void DoWork(object sender, DoWorkEventArgs e)
{
try
{
_backgroundWorkerThread = Thread.CurrentThread;
}
catch(ThreadAbortException)
{
}
}