Question Search Files

naduntha

Member
Joined
Aug 2, 2010
Messages
10
Location
Sri Lanka
Programming Experience
3-5
I used following vb code to search files of the windows. But during the search process the program is not responding and even it cannot move. Why this happened ? and how to solve the problem ?.

HTML:
Public Class Form1
    Dim list As Windows.Forms.ListViewItem

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        For Each file In My.Computer.FileSystem.GetFiles("C:\", FileIO.SearchOption.SearchAllSubDirectories)
            list = ListView1.Items.Add(file)
        Next

    End Sub
End Class
 
That would be because the form is so busy in that loop that it can't handle updating the UI at the same time, not till that loop finishes that is.

What you should do is move that code into a BackgroundWorker and I would update the UI after completing each folder (which means recursively searching the directories manually).

Also a ListView's Item's holds ListViewItem's not just any object like you're trying to do.
 
Back
Top