I have a process where my main thread is reading a file and splitting it into parts. Those parts then require further processing. I would like to utilize any available threads so that the downstream processing is utilizing as much CPU (or as many cores) as possible. I don't want to create an excessive backlog from the main thread, so I need the main thread to wait to add to the queue until there is another available thread.
I see many articles like VB.NET 4.0: Looking to execute multiple threads, but wait until all threads are completed before resuming, but they are waiting for all threads to complete, whereas I just need any threads to be available
Is this something I can tackle with the Task Parallel Library, or should I be manually creating threads and monitoring a threadpool?
Using Reader As New StreamReader(FileName)
Do
CurrentBlockSize = Reader.ReadBlock(CurrentBuffer, 0, BufferSize)
RunningBuffer &= New String(CurrentBuffer)
If RunningBuffer.Contains(RowDelimiter) Then
LineParts = RunningBuffer.Split(RowDelimiter)
For I As Integer = 0 To LineParts.Count - 1
If I < LineParts.Count - 1 Then
'Make synchronous call that blocks until'
'another thread is available to process the line'
AddLineToTheProcessingQueue(CurrentLine)
Else
RunningBuffer = LineParts(I)
End If
Next
End If
Loop While CurrentBlockSize = BufferSize
End Using