Cannot Get Task Parts to Work as Intended

RogerSchlueter-7899 1,256 Reputation points

I am trying to run a simulation in the TaskPool with updates to the UI thread. Here is what I've got so far:

Class MainWindow
    Private WithEvents Status As New Progress(Of Integer)

    Private Sub Run(sender As Object, e As RoutedEventArgs) Handles btnRun.Click
        <<Define CurrentScenario>>
        Dim cts As New CancellationTokenSource()
        Dim token As CancellationToken = cts.Token
                RunScenario(CurrentScenario, Status)
            End Sub)
    End Sub

    Private Shared Sub RunScenario(sc As Scenario, progress As IProgress(Of Integer))
        Iteration = 0          
        <<Perform iteration step>>
        Iteration += 1
    End Sub

    Private Sub UIWriter(I As Integer) Handles Status.ProgressChanged
        txtRes.Text = CStr(I)
    End Sub

End Class

This gives a compile-timer error: Method 'UIWriter' cannot handle event 'ProgressChanged' because they do not have a compatible signature.

I do not see how those two are inconsisternt.

In addition, to make this work, I have to add "WithEvents" to the definition of Status. In all the examples of similar code, I have not seen this which leads me to suspect that something else is also wrong.

Help is appreciated.

An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,663 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114.6K Reputation points

    Try this modification: Private Sub UIWriter(Sender as Object, I As Integer) Handles Status.ProgressChanged.

0 additional answers

Sort by: Most helpful