Avatar of Toni Stengler
Toni Stengler
 asked on

'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.')
Visual Basic.NET

Avatar of undefined
Last Comment
Toni Stengler

8/22/2022 - Mon
Éric Moreau

do you have code to share?

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

ASKER
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

ASKER CERTIFIED SOLUTION
Éric Moreau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Toni Stengler

ASKER
Thank You so much! This is exactly what I was looking for.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck