-1

I have implemented a WPF application using background worker in which I am assigning data from database to combobox.

I have used observable collection as ItemSource for combobox .

When I try to fill up the observable collection in DoWork method of background worker, UI is not getting updated but if I move same code to ProgressChanged or RunWorkerCompleted then it is working fine.

I want to know why the DoWork method is not updating the UI.Also the logic for updating UI should be in ProgressChanged or RunWorkerCompleted?

user3458219
  • 141
  • 1
  • 4
  • 11

2 Answers2

0

To quote MSDN : "You must be careful not to manipulate any user-interface objects in your DoWork event handler" - so in your DoWork method call ReportProgress event and update your ui in the ProgressChanged event handler

auburg
  • 1,373
  • 2
  • 12
  • 22
0

There are many online examples showing how to correctly utilise a BackgroundWorker. As you haven't bothered to show us your code, all we can do is guess, but I'm guessing that you simply haven't implemented your code properly. Not wanting to duplicate this code once again, I'd rather advise you to take a look at my answer to the Progress Bar update from Background worker stalling question here on Stack Overflow.

It clearly demonstrates how to implement a BackgroundWorker correctly.

Community
  • 1
  • 1
Sheridan
  • 68,826
  • 24
  • 143
  • 183