Backgroundworker won't report progress

前端 未结 6 992
情书的邮戳
情书的邮戳 2020-12-01 09:21

I have a background worker running a long database task. i want to show the progress bar while the task is running. Somehow the background worker won\'t report the progres

6条回答
  •  情歌与酒
    2020-12-01 10:18

    You need to call worker.ReportProgress(percentComplete) in your DoWork method. percentComplete should be computed based on the total work. For example:

    for(int i =0; i != 100; i++) {
        // do something
        worker.ReportProgress(i);
    }
    

    Sometimes it is difficult to partition a job in several chunks to be possible to report the progress. Unfortunately the BackgroundWorker does not solve this, you have to do it yourself.

提交回复
热议问题