Visual feedback on long running task

后端 未结 1 1781
[愿得一人]
[愿得一人] 2021-01-27 17:00

I have a long running for-each loop, and was wondering if there was a idiomatic way to add some visual user feedback so the user doesn\'t think the application crashed.

相关标签:
1条回答
  • 2021-01-27 17:35

    You could move the work to a BackgroundWorker and use the ReportProgress method.

    for (i = 0; i < count; i++)
    {
        // do work
        worker.ReportProgress((100 * i) / count);
    }
    
    private void MyWorker_ProgressChanged(object sender,
        ProgressChangedEventArgs e)
    {
        taskProgressBar.Value = Math.Min(e.ProgressPercentage, 100);
    }
    
    0 讨论(0)
提交回复
热议问题