To make it a little more straight forward, look at the following code:
static void Main(string[] args)
{
var bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.WorkerSupportsCancellation = true;
bw.RunWorkerAsync();
bw.CancelAsync();
Console.ReadLine();
}
static void bw_DoWork(object sender, DoWorkEventArgs e)
{
var bw = (BackgroundWorker) sender;
while (!bw.CancellationPending)
{
}
if (bw.CancellationPending)
{
e.Cancel = true;
}
else
{
bw.ReportProgress(100);
}
}