title: Start same thread twice - the second time after the first one finished
body: <p>So I made a Thread which executes one function which is dependent on a global variable. After that, I would like to change that variable and run the thread once again, so that it executes my procedure once again with another argument. The problem is, I can't seem to figure out when my Thread finished. After a lot of googling, I found nothing that could help me. Can someone here help ? Thanks in advance. Some code would be appreciated. Here is mine:</p>
  
  <pre><code>//temp_folder is global variable
  
  temp_folder = APPDATA + "Local" + "\\" + "Temp\\";
  
  Thread oThread = new Thread(new ThreadStart(clean_temp));
  oThread.Start();
  
  //Here I should wait for this oThread to finish, then change the temp_folder
  //variable mentioned in comment down and start once again
  
  //temp_folder = WINDIR + "\\" + "Temp\\";
  //oThread.Start();
  </code></pre>
  
  <p>Here is a clean_temp() procedure. And yes, this is GUI app.</p>
  
  <pre><code>public void clean_temp()
  {
  DirectoryInfo directory = new DirectoryInfo(temp_folder);
  
  try
  {
      DirectoryInfo[] folders = directory.GetDirectories();
  
      foreach (DirectoryInfo folder in folders)
      {
          temp_folder = temp_folder + folder.Name + "\\";
          clean_temp();
          temp_folder = temp_folder.Replace(folder.Name + "\\", "");
      }
  }
  catch { }
  
  long sz;
  double size, trenutna;
  
  foreach (FileInfo file in directory.GetFiles())
  {
      sz = file.Length;
      size = (double)sz / 1024.0;
      trenutna = Convert.ToDouble(lbl_junk_size.Text);
      trenutna += size;
  
      MethodInvoker mi_invoker_size_change = new MethodInvoker(()=&gt; lbl_junk_size.Text = trenutna.ToString());
      lbl_junk_size.Invoke(mi_invoker_size_change);
  
      MethodInvoker mi_invoker_count_change = new MethodInvoker(() =&gt; lbl_junk.Text = (Convert.ToInt64(lbl_junk.Text) + 1).ToString());
      lbl_junk.Invoke(mi_invoker_count_change);
  }
  }
  </code></pre>