title: How to prevent UI from freezing during lengthy process?
body: <p>I need to write a VB.Net 2008 applet to go through all the fixed-drives looking for some files. If I put the code in ButtonClick(), the UI freezes until the code is done:</p>
  
  <pre><code>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      'TODO Find way to avoid freezing UI while scanning fixed drives
  
      Dim drive As DriveInfo
      Dim filelist As Collections.ObjectModel.ReadOnlyCollection(Of String)
      Dim filepath As String
  
      For Each drive In DriveInfo.GetDrives()
          If drive.DriveType = DriveType.Fixed Then
              filelist = My.Computer.FileSystem.GetFiles(drive.ToString, FileIO.SearchOption.SearchAllSubDirectories, "MyFiles.*")
              For Each filepath In filelist
                  'Do stuff
              Next filepath
          End If
      Next drive
  End Sub
  </code></pre>
  
  <p>Google returned information on a BackGroundWorker control: Is this the right/way to solve this issue?
  If not, what solution would you recommend, possibly with a really simple example?</p>
  
  <p>FWIW, I read that Application.DoEvents() is a left-over from VBClassic and should be avoided.</p>
  
  <p>Thank you.</p>