0
I am creating in my main form a Backgroundworker object and I have two click events, one to activate and the other to disable the backgroundWorker, but the method to disable is not working.
BackgroundWorker worker;
public FrmPrincipal()
{
InitializeComponent();
worker = new BackgroundWorker();
worker.DoWork += worker_DoWork;
worker.WorkerReportsProgress = true;
worker.WorkerSupportsCancellation = true;
worker.ProgressChanged += worker_ProgressChanged;
worker.RunWorkerCompleted += worker_RunWorkerCompleted;
}
Boot:
private Ativar_Click()
{
worker.RunWorkerAsync();
}
Deactivate button:
private Desativar_Click()
{
worker.CancelAsync();
}
Event of the Do_work:
private void worker_DoWork(object sender, DoWorkEventArgs e)
{
while(true)
{
ClienteBusiness.Inserir();
}
}
He makes some mistake?
– Leonardo Pessoa
Do not give any error and even use Debug it goes through the worker.Cancelasync();
– Victor Freitas