title: Semaphore for control downloadinf process
body: <p>I use Semaphore In this code </p>
  
  <pre><code>static Semaphore s = new Semaphore(1,1);
  private void button2_Click(object sender, EventArgs e)
          {
  
                   Thread[] t = new Thread[full_list];
                   for(int i=0;i&lt;full_list;i++)
                   {    
                       if (sorted_list[i].audio_node != null)
                           if (sorted_list[i].audio_node.Checked == true)
                           {
                               t[i] = new Thread(DownloadFile);
                               t[i].Start(sorted_list[i]);
                           }
                    }
  
             }
  
  private  void DownloadFile(object a)
          {
              s.WaitOne();
              if (InvokeRequired)
              {
                  BeginInvoke(new DownloadFileDelegate(DownloadFile),new object[1] {a} );
                  return;
              }
              else
              {
                  download process....
  
                      }
                      catch (Exception ex)
                      {
                          MessageBox.Show(ex.Message);
                      }
                  }
              }
              s.Release();
          }
  </code></pre>
  
  <p>But it doesn't work, my prorgram freezes. I am trying solve this problem, but i don't know why it doesn't work with Semaphore. All components include downloading work correctly.</p>