【发布时间】:2015-01-29 23:26:10
【问题描述】:
我很难使用 Parallel.ForEach 和 ConcurrentDictionary 获得正确的语法。下面的 Parallel.ForEach 的正确语法是什么?
Dim ServerList as New ConcurrentDictionary(Of Integer, Server)
Dim NetworkStatusList as New ConcurrentDictionary(Of Integer, NetworkStatus)
... (Fill the ServerList with several Server class objects)
'Determine if each server is online or offline. Each call takes a while...
Parallel.ForEach(Of Server, ServerList, Sub(myServer)
Dim myNetworkStatus as NetworkStatus = GetNetworkStatus(myServer)
NetworkStatusList.TryAdd(myServer.ID, myNetworkStatus)
End Sub
... (Output the list of server status to the console or whatever)
【问题讨论】:
-
问题肯定出在 Parallel.ForEach 行。为了清楚起见,我已经包括了其他定义,但也许它只会引起更多的混乱。大声笑
标签: vb.net parallel-processing parallel.foreach