Recursive folder search gets during code execution 'not responding'
I have one button, one textbox and a listview. What I try is just recursivly loop trough my filesystem. For example, C:\Windows. Of course, the app needs go through hundred thousand directory's, this needs CPU and RAM performance. But the problem is, that my application window gets to a 'not responding' state during this time.
Can I avoid this behaviour by optimizing my code?
My VB.NET code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim rootDir As String = String.Empty
Dim di As DirectoryInfo
rootDir = TextBox1.Text.Trim()
di = New DirectoryInfo(rootDir)
' start recursively loop trough filesystem
recur_getdirectories(di, 0)
End Sub
Public Sub recur_getdirectories(ByVal di As DirectoryInfo, ByRef int As Integer)
int = int + 1
Try
For Each directory As DirectoryInfo In di.GetDirectories()
ListView1.Items.Add(directory.FullName)
Label1.Text = int
recur_getdirectories(directory, int)
Next
Catch ex As UnauthorizedAccessException
End Try
End Sub
from Recent Questions - Stack Overflow https://ift.tt/37OuLCn
https://ift.tt/eA8V8J
Comments
Post a Comment