Follow in Twitter & Facebook


Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools


Wednesday, April 25, 2012

This BackgroundWorker is currently busy and cannot run multiple tasks concurrently.









Introduction:
Here we will discuss about one InvalidOperationException, which I got while doing one demo using one BackgroundWorker control in case of a windows application by Vb.net. The Exception is like "This BackgroundWorker is currently busy and cannot run multiple tasks concurrently".

Description:
I got this InvalidOperationException, this Exception is like "This BackgroundWorker is currently busy and cannot run multiple tasks concurrently". I got this error when i was doing one demo in visual studio 2010 using that BackgroundWorker control in vb.net.

This is nothing but one InvalidOperationException. I got this one in the line BackgroundWorker1.RunWorkerAsync().
At that time my code looks like below

 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load     
        BackgroundWorker1.RunWorkerAsync()
    End Sub
    Private Sub BackgroundWorker2_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
        System.Threading.Thread.Sleep(1000)
    End Sub

Then i am searching for the solution, I got the solution like we can check first wheather the BackgroundWorker is already busy or free by the help of IsBusy Property.
Now my code looks like as follows:

 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not BackgroundWorker1.IsBusy Then
            BackgroundWorker1.RunWorkerAsync()
        Else
            MessageBox.Show("Can't run the worker twice!")
        End If
        BackgroundWorker1.RunWorkerAsync()
    End Sub
    Private Sub BackgroundWorker2_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
        System.Threading.Thread.Sleep(1000)
    End Sub

I am sharing the screenshot. It is as below..




0 on: "This BackgroundWorker is currently busy and cannot run multiple tasks concurrently."