2013-07-29 88 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