Threading / updating textbox question

B

Bmack500

Hello! And thanks in advance. I have the following code which just
basically creates a set of threads for me (Using svrList as my list of
class instances to thread). Let's call the threads workerthreads.

The worker threads need to update a textbox on Form1 as they progress.

The question is, how do I create the necessary delegates / whatever to
update the textbox in a thread - safe manner?

The classes created in svrList are all instances of serverClass with
data passed to them during creation.

'Seed threadCount to get it started
threadCount = 1
'Okay, keep going while threads still exist
'If ther are no threads, create a new one as long as there are objects
left in svrList
While threadCount <> 0
If threadList.Count < My.Settings.numThreads And
svrList.Count > 0 Then
Dim Server As serverClass = CType(svrList(0),
serverClass)
Dim svrThread As New Thread(AddressOf Server.getInfo)
threadList.Add(svrThread)
svrThread.Start()
svrList.Remove(Server)
threadCount = threadList.Count
End If
Dim iIndex As Integer = 0

For threadIndex = threadList.Count - 1 To 0 Step -1
sThread = CType(threadList(threadIndex), Thread)
If Not sThread.IsAlive Then
threadList.RemoveAt(threadIndex)
End If

Next

'Thread.Sleep(50)

End While
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top