I had to write a multithreaded program in vb that can process files in a directory simultaniusly. Th problem is that it runs fine for some hours. Then it suddenly stucks at the "Thread.Sleep(500)" because all the 3 thread isAlive method returns with "true" value, but "StartSub" are ended in all threads...and seems to be not terminating. Is my code wrong or what could be the problem?
Basicaly the program is like the following:
private sub main()
importThread = New Thread(AddressOf StartSub)
importThread2 = New Thread(AddressOf StartSub)
for each file in directory
While True
If importThread.IsAlive And importThread2.IsAlive Then
Thread.Sleep(500)
Else : Exit While
End If
End While
If importThread.IsAlive Then
importThread2 = New Thread(AddressOf StartSub)
importThread2.IsBackground = True
importThread2.Start()
Else
importThread = New Thread(AddressOf StartSub)
importThread.IsBackground = True
importThread.Start()
End If
next
End sub
Private Sub StartSub(ByVal tp As Object)
'Read fileinfo and process it for something
end Sub