Question ThreadPool and ListView items

CarcaBot

Well-known member
Joined
Apr 23, 2007
Messages
47
Location
Romania
Programming Experience
Beginner
first of all , hello to everyone who keep this forum alive.

I came with a problem which i can't solve it in any way since 2 days...
I can't be describe my problem concisely, but i hope you understand what i'm trying to do

I have 1 array of 10 items and I want to run a limited number of threads constantly from array using ThreadPool and add items to a ListView control but after to can modify some rows of that ListView control based on some functions.

The code which i'm using right now is:

Start
 For i As Integer = 0 To threads - 1
                ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf startjob), i)
            Next


Startjob function

 Private Sub startjob(ByVal index As Object)
        Dim threadid As Integer = index
        While myarray.Count > 0 ' i know that from here my problem started but don't know where
            Dim item As String = Nothing 'THE LISTVIEW ITEM
            Dim account As String = getAccount() ' this will get a variable from another array return string
            If (String.IsNullOrEmpty(account)) Then
                Exit Sub
            End If
            Dim acc() As String = account.Split(":")
            Dim str1  As String = acc(0)
            Dim str2 As String = acc(1)

            Dim items As ListViewItem
            items = ListView1.Items.Add(str1) '1
            items.SubItems.Add(str2) '2
            items.SubItems.Add("?") 'blacklist
            items.SubItems.Add("?") '4
            items.SubItems.Add("?") '5
            items.SubItems.Add("?") '6
            items.SubItems.Add("?") '7
            items.SubItems.Add("?") '8
            ListView1.Refresh()
            If Not isBlacklisted(str1) Then ' return true or false - when it return i want to update  items.SubItems.Add("?") 'blacklist
                'checking account
                Dim worker As New WorkHandler_CheckAccount(AddressOf CheckAccount)
                worker.BeginInvoke(str1, str2, AddressOf CheckAccountCallback, Nothing)
          End If 'if blacklisted
            index = ListView1.Items.Count() + 1
        End While
    End Sub


mention that I read about threadpool on msdn, plus the entire google, and I found no solution helpful.
thanks for ideas and help.
 
Back
Top