Link to home
Start Free TrialLog in
Avatar of godwindotnet
godwindotnet

asked on

Searching files and folders

Hello everyone..
I have this problem in making a simple search like the windows search to search files and folders.
I want it to search within the specified folder and subfolders inside it...and return all the files matching the query.

Here is what Ive tried.,.

code:--------------------------------------------------------------------------------
Dim s As String = TextBox1.Text
        For Each file As String In My.Computer.FileSystem.GetFiles("c:\", FileIO.SearchOption.SearchAllSubDirectories, s)
            ListView1.Items.Add(file)
        Next file
--------------------------------------------------------------------------------
.but the problem is...My program freezes till the search ends unlike the windows search.

Someone help...Thank you so much in advance :-)
Avatar of doobdave
doobdave

Hi there,

The problem you are experiencing is, I believe, related to threading (do a bit of reading up on this topic if you're not familier with the concepts).

Basically what is happening is that your form/UI and the 'search' function are all running in the same thread, which means that everything is executed in a sequential manner, and therefore each function must complete before the code moves on to the next one.

What you need to do is execute the Search function in a separate thread, which means it will go off and do its work, but your UI will remain responsive as it's running in its own thread.

The following code should help you, put it inside the button click event handler, or wherever it is you call the Search function:

Dim thr as System.Threading.Thread
thr = New system.Threading.Thread(AddressOf NameOfYourSearchSub)
thr.Start

Note that your search procedure should be a sub annd not a function and should not take in any parameters, or things become more complicated.

Hope this helps.

Best Regards,

David
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good point Idle_Mind, I should've noticed that!
Avatar of godwindotnet

ASKER

Idle_Mind,That wasnt the perfect solution though
Hi godwindotnet,

Then please give feedback so we know that the proposed solutions either didn't work or still don't perform as well as you want.

Without comments from you we will just assume that they solved the problem.

I'm almost always willing to give examples when they are asked for!

=)