2013-07-29 152 views
1

我用我application.I多线程的概念正在使用下面的代码状态的线程

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个编号的,我怎么能知道所有10个线程是否完成或没有。

+0

做什么你的意思是id's'' ManagedThreadId'? –

+0

我想他是在谈论10个不同的数据库ID –

+0

其唯一的ID为:1000至1010 – Sree

回答

0

您正在开始并逐个加入该线程。也就是说,不是你的意图。如果你保持这种方式创建单个线程,请等待它完成,然后才能继续下一个元素。

我会尝试以下方法:为每个线程将其添加到列表或数组和之后对于每一个/下一个语句,您可以加入他们所有的财产,我想,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 finish 
+0

我们如何为列表添加JoinAll – Sree

+0

我更改了JoinAll的调用。我现在没有VS,所以我正在做心脏,对不起 –

+0

感谢您的回答,我改变了它对于每个线程在所有线程 t.Join() Next – Sree