Wpf progressbar value not updating
changes: You can't see any changes because your Main thread AKA UI Thread is busy Sleeping and it does not have time to update your UI Let Task handle your lengthy job and Main thread for Updating UI Wrap your code inside Task and you can see your progress bar progressing.
The problem is that binding from a non-UI thread usually works until it doesn't - e.g. I made few changes to your sample as your file downloaded is working on UI thread and application just freezes you can see it by changing focus to other application and trying to get back - window will not appear nor update.If you make them ordinary, non-auto properties, you can still use data binding to connect them to the UI.To get the UI to update when the properties change, you'll need to implement , and you make your properties raise change notifications, then you'll find that you're able to do work on a worker thread as in your first example, and if you bind those properties to the UI, you won't get threading exceptions, and it'll update just fine.(WPF's data binding system detects when a bound property changes on a thread other than the UI thread, and automatically arranges to update the UI from the correct thread.But you can't use DPs in your VM if you want to take advantage of this, because DPS have thread affinity.) The style approach someone else proposed does work but it is problematic and I avoid it.I am using a wpf User Control to replace text in files in selected drawing files of Auto CAD.
The wpf control is to display a status (Progress Bar) indicating the number of files processed at any given time.
But if you've got a load of work to do in a loop, then that's not really practical.
So in general, you don't want to do this sort of work on the UI thread.
The Progress Bar does not respond to property change, however. The constructor of the VM starts a model on a TPL thread. So putting it all together, the model is running in its own thread, and the UI is being updated on its own thread. The Progress Bar will increment its way up to 100 and the UI will remain responsive while the model is doing its work.
This answer does not explain why your original code does not work, but I suspect it has to do with the UI thread being starved out.
Edit: In Order to process the Progress Bar update code on UI thread, I changed my code to use Background Worker. Code Behind for User Control: I created a test project with your initial code.