Hello,
Im a noob but am trying to learn. Ive found a way to make VB useful for a task ive been given to copy thousands of files to a slow SAN server daily. Right now i copy one file at a time. it works. painfully slow but it works.
What id like to do is come up with some kind of stack where i can add filenames to copy to the stack. Call some code to spawn X number of threads and one by one it chews away at the stack. popping each file off the stack, copying it and then
taking another off the stack until it's done then ending gracefully.
Umm yeahhh. my code isnt even close. I got the multi-threading to work. But i cant seem to get control of one thread taking a file from the top and the second thread takes the next one down etc. The way i have it all three threads seem to grab the same top item in the stack. its a mess. Well any ideas on how i should be doing this? I appreciate the help. Thank you!
Im a noob but am trying to learn. Ive found a way to make VB useful for a task ive been given to copy thousands of files to a slow SAN server daily. Right now i copy one file at a time. it works. painfully slow but it works.
What id like to do is come up with some kind of stack where i can add filenames to copy to the stack. Call some code to spawn X number of threads and one by one it chews away at the stack. popping each file off the stack, copying it and then
taking another off the stack until it's done then ending gracefully.
Umm yeahhh. my code isnt even close. I got the multi-threading to work. But i cant seem to get control of one thread taking a file from the top and the second thread takes the next one down etc. The way i have it all three threads seem to grab the same top item in the stack. its a mess. Well any ideas on how i should be doing this? I appreciate the help. Thank you!
Imports System Module Module1 Public FileStack As New Stack(Of String) Sub FCT1() Try Console.WriteLine("FCT1: " & FileStack.Peek) FileStack.Pop() Catch ex As Exception Console.WriteLine("Error: FCT1") End Try 'Do actual file copy to SAN End Sub Sub FCT2() Try Console.WriteLine("FCT2: " & FileStack.Peek) FileStack.Pop() Catch ex As Exception Console.WriteLine("Error: FCT2") End Try 'Do actual file copy to SAN End Sub Sub FCT3() Try Console.WriteLine("FCT3: " & FileStack.Peek) FileStack.Pop() Catch ex As Exception Console.WriteLine("Error: FCT3") End Try 'Do actual file copy to SAN End Sub Sub Main() FileStack.Push("1.PDF") FileStack.Push("2.PDF") FileStack.Push("3.PDF") FileStack.Push("4.PDF") FileStack.Push("5.PDF") If FileStack.Count > 0 Then Console.WriteLine("Copying " & FileStack.Count.ToString & " files...") Else Console.WriteLine("No files to copy.") End If Do While FileStack.Count > 0 Dim A As System.Threading.Thread = New Threading.Thread(AddressOf FCT1) Dim B As System.Threading.Thread = New Threading.Thread(AddressOf FCT2) Dim C As System.Threading.Thread = New Threading.Thread(AddressOf FCT3) A.Name = "File_Copier_Thread_1" B.Name = "File_Copier_Thread_2" C.Name = "File_Copier_Thread_3" A.Start() B.Start() C.Start() Loop Console.ReadLine() End Sub End Module