title: Threading and Recursion in C#
body: <p>I have this function which takes a path and searches for a file in it. I have two approaches: one is to make the main thread do the job, and the another is to make a worker thread do the job. When the main thread does the job it returns all the files but when a worker thread does the job it returns only a small number of the files in that path only. It doesn't do the recursion step which enters sub-directories. Here is the code:</p>
  
  <pre><code>public void  GetAllFiles(string sdir)
          {
  
                  foreach (string dir in Directory.GetDirectories(sdir))
                  {
  
                      try
                      {
                          foreach (string file in Directory.GetFiles(dir, "*.*"))
                          {
                              string filename = Path.GetFileName(file);
  
                              listView1.Items.Add(filename);
  
                          }
                          GetAllFiles(dir);
                      }
                      catch (Exception error)
                      {
                          Console.WriteLine(error.Message);
                      }
                  }
              } 
  </code></pre>
  
  <p>and here is how i call the thread:</p>
  
  <pre><code> Thread thread = new Thread(() =&gt; GetAllFiles("C:\\Users\\modz\\Desktop\\games"));
   thread.Start();
  </code></pre>