-1
Hello, I am with the following message, it is the first time q I am working with Backgroundworker and I run a long function inside the function (Dowork) of the Backgroundworker however it happens this message and does not run this lbMSG is a LABEL where I show some messages, So what I did I commented the LABEL but ai error in other parts with the same message. ( System.Invalidoperationexception: 'Invalid threading operation: 'lbMSG' control accessed from a thread that is not the one in which it was created.' )
This is the code of (Dowork)
private void bcwLeDbf_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
//Executa a tarefa
ConectaDBF("select * from " + CaminhoArquivo);
//Verifica se houve uma requisição para cancelar a operação.
if (bcwLeDbf.CancellationPending)
{
//se sim, define a propriedade Cancel para true
//para que o evento WorkerCompleted saiba que a tarefa foi cancelada.
e.Cancel = true;
return;
}
}
If anyone has any tips thank you.
you have the Connected variablebf and Hike?
– Filipe P.R
Backgroundworker works on a thread other than the main thread of the application where the visual part is created... so you can’t just access a control that was created in the main thread from within the backgroundworker. For an appropriate response, you should have the method code
ConectaDBF
without this I cannot point out where the error is. Take a look at other examples of background worker, and how to use the report Progress. There is also the option to use theInvoke
: https://answall.com/a/324491/69359– Rovann Linhalis