我在我的应用程序中使用了一个多线程概念。
Dim threadHistory As Thread = Nothing
For Each dRow As DataRow In sqlDS.Tables(0).Rows
GetPropertyBidHistory(dRow("ID"))
threadHistory = New Threading.Thread(AddressOf GetRowHistory)
threadHistory.Name = "Row" + dRow("ID")
threadHistory.Start(dRow("ID"))
threadHistory.Join()
Next
Public Sub GetRowHistory(ByVal ID As String)
'1 min code from web srvice
End Sub如果我有10个Id,我如何知道所有10个线程是否已经完成。
发布于 2013-07-29 15:38:37
你一个接一个地开始和加入这个线程。这也许不是你的意图。如果您将其保持为创建单个线程的方式,则等待它完成,然后才继续到下一个元素。
我会尝试以下方法:对于每个线程,将其添加到一个列表或数组中,在for all /Next语句之后,您可以使用属性加入它们,我猜是JoinAll()
Dim List( Of Thread) allThreads = new List
Dim threadHistory As Thread = Nothing
For Each dRow As DataRow In sqlDS.Tables(0).Rows
GetPropertyBidHistory(dRow("ID"))
threadHistory = New Threading.Thread(AddressOf GetRowHistory)
threadHistory.Name = "Row" + dRow("ID")
allThreads.Add(threadHistory)
threadHistory.Start(dRow("ID"))
Next
Thread.JoinAll(allThreads) 'Blocks until all the threads finishhttps://stackoverflow.com/questions/17928079
复制相似问题