B
brett
I have a program written in VB.NET using the 3.5 framework.
What the program does:
Searches a list of folders on a remote server for all files with
the .PST extension and reports it back in a text box list and also
outputs to a csv file.
My question:
There are approx 800,000 files that are to be searched through to get
my listing. The way that the program is working so far is really
slow, about 4 hours to complete. The following is a bit of code that
does my searching. How can i make this faster?
Private Sub search_loop(ByVal sdir As String)
Try
For Each fname As String In IO.Directory.GetFiles(sdir)
total_files += 1
Dim d3 As New SetTextCallback(AddressOf filesSearched)
Me.Invoke(d3, New Object() {total_files.ToString})
If fname.EndsWith("pst") Then
psts_found += 1
Dim d4 As New SetTextCallback(AddressOf pstsFound)
Me.Invoke(d4, New Object() {psts_found.ToString})
Dim NewText As String = fname
' Check if this method is running on a different
thread
' than the thread that created the control.
If Me.pst_found_box.InvokeRequired Then
' It's on a different thread, so use Invoke.
Dim d2 As New SetTextCallback(AddressOf
SetText2)
Me.Invoke(d2, New Object() {[NewText] + vbCr})
Else
' It's on the same thread, no need for Invoke.
Me.pst_found_box.AppendText([NewText] + vbCr)
End If
Else
Dim NewText As String = fname
' Check if this method is running on a different
thread
' than the thread that created the control.
If Me.pst_status_box.InvokeRequired Then
' It's on a different thread, so use Invoke.
Dim d As New SetTextCallback(AddressOf
SetText)
Me.Invoke(d, New Object() {[NewText] + vbCr})
Else
' It's on the same thread, no need for Invoke.
Me.pst_status_box.AppendText([NewText] + vbCr)
End If
End If
Next
For Each subdir As String In IO.Directory.GetDirectories
(sdir)
search_loop(subdir)
Next
Catch ioex As System.UnauthorizedAccessException
Dim d5 As New SetTextCallback(AddressOf SetText)
Me.Invoke(d5, New Object() {ioex.ToString + vbCr})
Catch generatedExceptionName As Exception
Dim d6 As New SetTextCallback(AddressOf SetText)
Me.Invoke(d6, New Object()
{generatedExceptionName.ToString + vbCr})
End Try
End Sub
What the program does:
Searches a list of folders on a remote server for all files with
the .PST extension and reports it back in a text box list and also
outputs to a csv file.
My question:
There are approx 800,000 files that are to be searched through to get
my listing. The way that the program is working so far is really
slow, about 4 hours to complete. The following is a bit of code that
does my searching. How can i make this faster?
Private Sub search_loop(ByVal sdir As String)
Try
For Each fname As String In IO.Directory.GetFiles(sdir)
total_files += 1
Dim d3 As New SetTextCallback(AddressOf filesSearched)
Me.Invoke(d3, New Object() {total_files.ToString})
If fname.EndsWith("pst") Then
psts_found += 1
Dim d4 As New SetTextCallback(AddressOf pstsFound)
Me.Invoke(d4, New Object() {psts_found.ToString})
Dim NewText As String = fname
' Check if this method is running on a different
thread
' than the thread that created the control.
If Me.pst_found_box.InvokeRequired Then
' It's on a different thread, so use Invoke.
Dim d2 As New SetTextCallback(AddressOf
SetText2)
Me.Invoke(d2, New Object() {[NewText] + vbCr})
Else
' It's on the same thread, no need for Invoke.
Me.pst_found_box.AppendText([NewText] + vbCr)
End If
Else
Dim NewText As String = fname
' Check if this method is running on a different
thread
' than the thread that created the control.
If Me.pst_status_box.InvokeRequired Then
' It's on a different thread, so use Invoke.
Dim d As New SetTextCallback(AddressOf
SetText)
Me.Invoke(d, New Object() {[NewText] + vbCr})
Else
' It's on the same thread, no need for Invoke.
Me.pst_status_box.AppendText([NewText] + vbCr)
End If
End If
Next
For Each subdir As String In IO.Directory.GetDirectories
(sdir)
search_loop(subdir)
Next
Catch ioex As System.UnauthorizedAccessException
Dim d5 As New SetTextCallback(AddressOf SetText)
Me.Invoke(d5, New Object() {ioex.ToString + vbCr})
Catch generatedExceptionName As Exception
Dim d6 As New SetTextCallback(AddressOf SetText)
Me.Invoke(d6, New Object()
{generatedExceptionName.ToString + vbCr})
End Try
End Sub