I have a backgroundworker. When it start it call a method to send record from a database to another webservice.
Problem is I made a stop button to stop the job sending but it didn't work.
I try to dispose backgroundworker or CancelAsync but that method still running (My app is a windows form app so I know that method is still running). Anyone can give me a solution for this ? Tks so much!
My code :
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
Send();
}
Stop button
private void btnStop_Click(object sender, EventArgs e)
{
try
{
backgroundWorker1.CancelAsync();
backgroundWorker1.Dispose();
}
catch (Exception ex)
{
Global._logger.Info(ex.Message + ex.Source);
ShowError(ex.Message);
}
}
Note : The method Send() will call another method to send record after checking DB.