'This operation has already had OperationCompleted called on it and further calls are illegal.'

'This operation has already had OperationCompleted called on it and further calls are illegal.'

I am using vb.net and I am using a backgroundworker to download files when I call the ReportProgress the first time works but when I call it again further down the code of the Backgroundworker_dowork event it shows the error above ('This operation has already had OperationCompleted called on it and further calls are illegal.')
Toni StenglerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
do you have code to share?

if your task is already completed, you shouldn't trigger the event.
Toni StenglerAuthor Commented:

 Private Async Sub DownloaderWorkerAsyncOne_DoWork(sender As Object, e As DoWorkEventArgs) Handles DownloaderWorkerAsyncOne.DoWork

            Dim DownloadID As String = CStr(e.Argument)
            Dim CurrentDownloadPath As String = downloadsPath + DownloadID + "\"
            Dim CurrentDownloadFolder As StorageFolder
            Dim query As String = Await Pixels_Project_API.API.v1.GetVideo(CInt(DownloadID))
            DownloaderWorkerAsyncOne.ReportProgress(0, DownloadID + ":" + "Waiting")
                CurrentDownloadFolder = Await downloadsFolder.CreateFolderAsync(DownloadID, CreationCollisionOption.FailIfExists)
            Catch ex As Exception
                Alert("Error", "Folder exist")
                Exit Sub
            End Try
            DownloaderWorkerAsyncOne.ReportProgress(1, DownloadID + ":" + "Preparing") 'ERROR HERE 
//More code 
        End Sub

        Private Sub DownloaderWorkerAsyncOne_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles DownloaderWorkerAsyncOne.ProgressChanged
            Dim IDandState As String() = e.UserState.ToString.Split(":")
            ReportWork(CStr(IDandState(0)), CStr(IDandState(1) + ":" + CStr(e.ProgressPercentage) + "%"))
        End Sub

 Private Async Sub ReportWork(ob As String, status As String)
            Dim StatusProgress As String() = status.Split(":")
            For Each down As DownloadControl In ActiveDownloads.Children
                If down.MovieID = ob Then
                    down.Status = StatusProgress(0)
                    down.Progress = StatusProgress(1)
                    Exit For
                End If

        End Subhttps://www.experts-exchange.com/questions/29134964/'This-operation-has-already-had-OperationCompleted-called-on-it-and-further-calls-are-illegal-'.html#a42792335

Open in new window

Éric MoreauSenior .Net ConsultantCommented:
It seems that async operations and the BackgroundWorker component are not working well with each other. Have a look https://stackoverflow.com/questions/28230363/operation-already-completed-error-when-using-progress-bar

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Toni StenglerAuthor Commented:
Thank You so much! This is exactly what I was looking for.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.