I am trying to use this code in a multi-threaded WPF Visual Basic .NET application:
Private Sub RecursiveSearch(ByVal strPath As String, ByVal strPattern As String, ByRef lstTarget As ListBox)
Dim strFolders() As String = System.IO.Directory.GetDir
Dim strFiles() As String = System.IO.Directory.GetFil
Dim clsFile As FileInfoEx = Nothing
'Add the files
For Each strFile As String In strFiles
clsFile = New FileInfoEx(strFile)
'Look through the other folders
For Each strFolder As String In strFolders
'Call the procedure again to perform the same operation
(Sourced from here http://vbcity.com/forums/t/136964.aspx
This code works really well for recursively finding files that match a specific pattern by walking down a directory structure of folders and sub-folders.
The problem comes in with the fact that I am trying to run it on a separate thread and update a listbox with entries *as the files are found*. Becuse the folders I will be running this on can contain tens of thousands of files, the application seems to be unresponsive while the search is running and as such, I want to update the UI as each matching file is found and added to te list.
I have tried using backgroundworkers, delegates and threads but I cannot get it to work - I get all manner of errors from claims that the backgroundworker does not report progress (even though the property for it is set to do so) and on other occasions nothing happens, thread-lcock errors occur, etc.
Please help - just a simple (tested) example of running this type of file search on a thread that updates the UI will be much appreciated.