This BackgroundWorker is currently busy and cannot run multiple tasks concurrently

前端 未结 4 939
野趣味
野趣味 2020-12-08 04:06

I get this error if I click a button that starts the backgroundworker twice.

This BackgroundWorker is currently busy and cannot run multiple tasks concurrent         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-08 04:42

    Create a new BackgroundWorker object for each operation that you want to perform. I.e., rather than:

    BackgroundWorker worker = new BackgroundWorker();
    worker.DoWork += new DoWorkEventHandler(worker_DoWork);
    for (int i; i < max; i++) {
       worker.RunWorkerAsync(i);
    }
    

    Try this:

    for (int i; i < max; i++) {
       BackgroundWorker worker = new BackgroundWorker();
       worker.DoWork += new DoWorkEventHandler(worker_DoWork);
       worker.RunWorkerAsync(i);
    }
    

提交回复
热议问题