If I start a thread for the following subroutine, I will get a fileopen conflict (the file will be in use conflict), otherwise, if I simply call the routine without using a thread there won't be a conflict. For some reason, it seems that threading causes the loop to get "ahead of itself" such that the file does not close in time?
Dim t As New Thread(Addressof ProcessFile())
t.start --> causes file in use error
Call Processfile() --> does not cause file access error
For i As Integer = 1 to 10
Fileclose(1) 'Close for safety sake
FileOpen(101, myfile, OpenMode.Input)
.... Process data
Basically, when the thread is used, it seems that the file processing inside the loop is not sequential since the file does not close in time for the next loop increment. Basically, it appears that the loop is almost done in parallel, such that the value of i=1,2,...,10 is not really followed sequentially.
Basically, threading seems to override sequential operations in loops?