2
I’m using the BackgroundWorker
private BackgroundWorker BGWorker = new BackgroundWorker();
BGWorker.DoWork += BGWorker_DoWork;
BGWorker.RunWorkerAsync();
private void BGWorker_DoWork(object sender, DoWorkEventArgs e)
{
ObterInformacoes();
}
private void BGWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
dgv.ItemsSource = ObterInformacoes();
}
private List<Informacoes> ObterInformacoes()
{
List<Informacoes> func = gestores.gInfo.Recuperar(new Filtro[] {
new Filtro(eInfo.Ativa, true),
new Filtro(eInfo.Recorrente, false)
}).Select(f => new Informacoes(f)).ToList();
return func.OrderBy(f => f.Nome).AsParallel().ToList();
}
And it’s returning to me this mistake:
Additional information: It is necessary to create Dependencysource in the same Thread that Dependencyobject.
Does anyone know what it can be?
The list processing is done in the seprada thread, using the
BackGroundWorker
and upon completion of processing he notifies that he has finished passing the list asResult
to theBGWorker_RunWorkerCompleted
responsible for displaying the data processed.– Richard Dias
@Richarddias I may be wrong, but I believe your intention in the method
BGWorker_RunWorkerCompleted
was to writedgv.ItemsSource = lista
, instead of calling again the methodObterInformacoes
. Also, instead of creating thevar lista
inBGWorker_DoWork
, the correct would not be to assign the result to the propertye.Result
?– Conrad Clark
That’s right @Conradclark. Thank you very much for the comments. I’ve updated the response.
– Richard Dias
Are you using the
AsParallel
still? Post more details about the error.– Richard Dias
But in doing so, it makes no sense to use the
BackGroundWorker
– Richard Dias
Add more information about:
gestores.gInfo
– Richard Dias
I managed to solve the problem in my class
Informacoes
I have a property that is a photo. I addedFoto.Freeze()
and is working properly. I am using thee.Result
as suggested in the reply! Thank you.– MeuChapeu