Background worker cancel event is not entering the cancellpending condition

Background worker cancel event is not entering the cancellpending condition ..... it is looping in the btncancel_Click loop...... can any one tell me what may be the problem


private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{

someclass obj = new someclass ();
BackgroundWorker worker = sender as BackgroundWorker;
e.Result = obj.startprocess(someid, worker , e);
if (worker .CancellationPending)
{
e.Cancel = true;
}}


private void btncancel_Click(System.Object sender,
System.EventArgs e)
{
/// IT IS LOOPING IN THIS BUTTON CLICK EVENT
this.backgroundWorker1.CancelAsync();

}

// this function is in a class in other package

public bool startprocess(String someid, BackgroundWorker bw, DoWorkEventArgs e)
{
bool bRet = false;
if (bw.CancellationPending)
{
// WHEN I CLICK THE CANCEL BUTTON IT IS NOT ENTERING THIS CONDITION
System.Windows.Forms.MessageBox.Show(bRet.ToString());
e.Cancel = true;
}

else
{

try
{
somecode
if (bRet)
{
processing code
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
return bRet;

}
}


Answer this question

Background worker cancel event is not entering the cancellpending condition

  • Background worker cancel event is not entering the cancellpending condition