wpf progressbar doesn't update on last ProgressChanged

后端 未结 1 881
忘了有多久
忘了有多久 2021-01-25 05:03

I making some UI and I have ProgressBar in it. Using MVVM pattern.

XAML:



        
1条回答
  •  清酒与你
    2021-01-25 05:28

    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.

    0 讨论(0)
提交回复
热议问题