I have searched as long as my eyes can take it and can't find quite the solution I need. I'm creating an application that will run multiple SQL queries against a data set and rather than wait for each to finish in turn, I would like to kick off 2 at a time (using different threads for each). The following code seems to work to create one additional thread that works, but anything beyond that seems to get destroyed (or doesn't work).
'First I create a data reader that determines how many total SQL queries need to be run
'I then loop through them...and I'm TRYING (failing) to run 2 concurrently...then waiting
'for them to finish...then moving on to the next 2
'Inside the RUNSQL class, I'm just running a simple statement and getting one value back...
'What is really strange is that if I run this in debug mode and step through it, it works...so
'the code must be stepping on itself in "real time"
'In the real code I'm trying to run 5 threads, but I've cut it back for brevity sake
If oRST.HasRows Then
Dim intCounter As Integer = 0
Dim oThread(1) As System.Threading.Thread
Dim oRunSQL As New RunSQL
Do While 1 = 1
intFTPKey = oRST.Item("ftp_key")
If Err.Number <> 0 Then Exit Do
strSQL = oRST.Item("ifs_sql").ToString
oThread(intCounter) = New Thread(AddressOf oRunSQL.Runner)
oRunSQL.vSQL = strSQL 'This is where I pass the unique SQL statement to the new thread
oThread(intCounter).IsBackground = True
intCounter = intCounter + 1
If intCounter = 1 Then
intCounter = 0
Anyone know what the heck I'm missing here???