I making some UI and I have ProgressBar in it. Using MVVM pattern.
XAML:
For any future reader:
BackgroundWorker's DoWork
is performed on a new thread, allowing work to occur without locking the UI for instance. The RunWorkerCompleted
functionality will be ran on the calling thread for you, this means it is back on the UI thread and any work done here can lock the UI.
ProgressBar is being updated via different thread, allowing it to update. But as soon as the value goes from 90 to 100, the UI is performing this Close. When OP added the Sleep(5000); it was in the Completed which is the UI thread thus preventing the ProgressBar from showing a full 100%.
Resolution is to move the sleep from Completed into the DoWork loop, or at least after the loop, to see the ProgressBar hit 100%, before sending the close.