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

Toni Stengler
Toni Stengler used Ask the Experts™
on
'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.')
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
do you have code to share?

if your task is already completed, you shouldn't trigger the event.

Author

Commented:
LINE 7 WORKS FINE BUT FOR SOME REASON LINE 14 GIVES ME THE ERROR CODE ABOVE

 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")
            Try
                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
            Next


        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

Senior .Net Consultant
Top Expert 2016
Commented:
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

Author

Commented:
Thank You so much! This is exactly what I was looking for.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial