This BackgroundWorker is currently busy and cannot run multiple tasks concurrently

前端 未结 4 941
野趣味
野趣味 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:31

    I would look into queue'ing the tasks that need to be done. You get the following advantages;

    • You do not have to handle the problems of background tasks not being able to start due to something else already running
    • You do not have to worry about using up too many threads, by creating a new background worked for each task.
    • Lastly the queue could allow you to ensure that the background tasks run in the same order as they where created/requested.

    Here is an example implementation: http://thevalerios.net/matt/2008/05/a-queued-backgroundworker. I am not sure if the implementation in threadsafe, and I will update my answer once I figure out of my current locking problem in a implementation I am working with.

提交回复
热议问题