title: "For Each" loop : Application Freeze in Vb.net
body: <p>I am using the following code to get the size of files inside a directory 
  and put it in <code>Label1</code>:</p>
  
  <pre><code>For Each foundFile As String In My.Computer.FileSystem.GetFiles( _
     "\windows",Microsoft.VisualBasic.FileIO.SearchOption.SearchTopLevelOnly,_
     "*.*")
          Dim filesizelabel As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(foundFile)
          Label1.Text = Label1.Text + filesizelabel.Length
      Next
  </code></pre>
  
  <p>The problem is that i have more than 50 for each loops (a system cleaning app).</p>
  
  <p>When I run the loops my app freezes until the loops finish, even if I run one loop.</p>
  
  <p>Is there a solution to make it show the name of the current file? I tried this as well, but it also froze my application:</p>
  
  <pre><code>label2.text = foundfile
  </code></pre>
  
  <p>The application does not respond to any click, until it finishes the loops.  It shows the size in <code>Label1</code> and the last scanned file in <code>Label2</code>.  This also freezes the application:</p>
  
  <pre><code>system.threading.thread.sleep(100)
  </code></pre>
  
  <p><strong>Is there any alternative to foreach or a solution to fix this issue?</strong></p>