CodeLiftsleep
Member
- Joined
- Mar 11, 2016
- Messages
- 20
- Programming Experience
- 3-5
Not sure what I am doing wrong, but I can't get it to work. I am doing a CPU intensive task where I am creating a large number of players for a football game I am making, and I am using the Task.Factory.StartNew method to run it on. I then create a separate task for the Progress updater but I can't seem to get it to work.
I have a WPF progressbar which I have bound to an INotifyPropertyChanged Property, however it does not update and the UI appears frozen, which I thought tasks were supposed to eliminate...
Any help would be appreciated, and if you could let me know the how's and why's I would appreciate it as well so I can learn...
I have a WPF progressbar which I have bound to an INotifyPropertyChanged Property, however it does not update and the UI appears frozen, which I thought tasks were supposed to eliminate...
VB.NET:
TimeIt(Sub() ReallyGenNewPlayers())
Private Sub TimeIt(MyAction As Action)
Dim SW As New Stopwatch
SW.Start()
MyAction()
Console.WriteLine($"Total Time Generating Players: {SW.Elapsed} seconds")
SW.Stop()
End Sub
Private Sub ReallyGenNewPlayers()
Task.Factory.StartNew(Sub() GenNewPlayersASync()).Wait()
End Sub
Private Sub GenNewPlayersASync()
Dim x As Integer = 0
'Generate the Players on an Async Thread
For i As Integer = 1 To NumPlayers
x = i
Task.Factory.StartNew(Sub() CollegePlayers.GenDraftPlayers(x, MyDraft, DraftDT, DraftClass, PosCount)).Wait()
Dim mytask As Task(Of Double) = Task(Of Double).Factory.StartNew(Function() UpdateProgressBar(x, NumPlayers))
ProgBarValue = mytask.Result
Next i
End Sub
Private Function UpdateProgressBar(ByVal playernum As Integer, ByVal TotalPlayers As Integer) As Double
Dim myval As Double
Return myval = (playernum / TotalPlayers) * 100
End Function
Any help would be appreciated, and if you could let me know the how's and why's I would appreciate it as well so I can learn...