Having a bit of an issue with my file.scanner and that issue is that I cannot figure out how to run multi.threading when searching the files within a folder(8,000+ files).
Imports System.IO
Module x
Function xGetFolderFilesCount(ByVal selFolder As String) As Integer
If Directory.Exists(selFolder) Then Return Directory.GetFiles(selFolder).Length Else Return 0
End Function
Function xLoadFolderFiles(ByVal selFolder As String, Optional ByVal searchPattern As String = "*", _
Optional ByVal searchOption As SearchOption = SearchOption.TopDirectoryOnly) As Array
If Directory.Exists(selFolder) Then Return Directory.GetFiles(selFolder, searchPattern, searchOption) Else Return Nothing
End Function
End Module
Public Class Form1
Public myFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\TEMP.FILES\"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not xGetFolderFilesCount(myFolder) = 0 Then
For Each itm As String In xLoadFolderFiles(myFolder)
'// Run multi.threading here.
'MsgBox(itm)
Next
End If
End Sub
End Class
I tried System.Threading.Thread
and using the following...
Private Sub scanFile()
If Me.InvokeRequired Then
Me.Invoke(New MethodInvoker(AddressOf scanFile))
Else
'// code here to scan file.
End If
End Sub
...which returned the search.results at the same rate as it did without using the System.Threading.Thread
.
Any and all input on this issue is welcomed.
Thanks in advance,
.Me