我想询问是否可以更新并发数据结构中的对象。截至目前,我在我的UI类中有这个代码:
Dim myList As New List(Of Person)
Dim cancelToken As New CancellationTokenSource
Dim options As New ParallelOptions
options.CancellationToken = cancelToken.Token
Task.Factory.StartNew(Sub() ParallelForEach(someOtherList, options, Sub(person)
DoWork(boss, myList)
End Sub),myList,cancelToken.Token,TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext())
Private Sub DoWork(ByVal boss as Boss, ByVal myList as List(Of Person)
dim person as new Person
person.Name = "Andy"
person.Boss = boss.Supervisor1
myList.Add(person)
' Display in gridview
Dim index as Integer = myList.FindIndex(Function(p) p.Name = "Andy")
myList(index).Boss = boss.Supervisor2
' Refresh Gridview
End Sub
有人可以在此提出任何建议吗?