Try this modification: Private Sub UIWriter(Sender as Object, I As Integer) Handles Status.ProgressChanged.
Cannot Get Task Parts to Work as Intended
RogerSchlueter-7899
1,446
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
Task.Factory.StartNew(
Sub()
RunScenario(CurrentScenario, Status)
token.ThrowIfCancellationRequested()
End Sub)
cts.Dispose()
End Sub
Private Shared Sub RunScenario(sc As Scenario, progress As IProgress(Of Integer))
Iteration = 0
<<Perform iteration step>>
Iteration += 1
progress.Report(Iteration)
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.
Developer technologies | VB
2,894 questions