Making a progress bar update in real time in wpf

前端 未结 3 1996
我在风中等你
我在风中等你 2020-12-14 18:13

I\'m having some trouble making the progress bar show the updates in real time.

This is my code right now

for (int i = 0; i < 100; i++)
{
     pr         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 18:59

    You should use BackgroundWorker included in .NET, which provides you with methods for reporting the progress of a background thread in an event. The thread which created the BackGroundWorker automatically calls this event.

    The BackgroundWorker.ProgressChanged can be used to report the progress of an asynchronous operation to the user.

    // This event handler updates the progress bar. 
    private void backgroundWorker1_ProgressChanged(object sender,
        ProgressChangedEventArgs e)
    {
        this.progressBar1.Value = e.ProgressPercentage;
    }
    

    Refer to MSDN for more information about using this.

提交回复
热议问题