title: Running a progress bar using Background Controller in c#
body: <p>I don't have a thorough knowledge about controlling threads in c#. I want to create a progress bar while running a method. </p>
  
  <p>I have two forms:</p>
  
  <ol>
  <li><p><code>Form1</code> is the form which show up as you run the app. It has a button called <code>btnScrape</code>. When it is clicked the method should be called, the form with the progress bar should show up. <code>Form1</code> should be disabled to the user until the progress bar is completed.</p></li>
  <li><p><code>ProgressBarForm</code> - this has the progress bar and a label.</p></li>
  </ol>
  
  <p>The code is as follows.</p>
  
  <pre><code>   //In Form1.cs I have a button.
        private void btnScrape_Click(object sender, EventArgs e)
      {
              //gather data for folloeing parameters from the form.
               Controller cntrlr = new Controller(urlFilePath, destinationPath, destinationfilename,cmbDepth.SelectedIndex);
  
              cntrlr.Vmain(); // this is the method in controller class. while this is running i want show the progress bar.
      }
  
     // in Contrller class     
      class Controller{
            List&lt;string&gt; urlList = null; 
            URLFileReader urlFileReader = null;
            HTTPWorker httpWorker = null;
            SourceReader srcreader = null;
            ReportWriter reportWriter = null;
  
             string urlFilePath, destinationPath, destinationFileName;
             int depth;
  
      public Controller(string urlFilePath,string destinationPath,string destinationFileName,int depth)
      {
          this.urlFilePath = urlFilePath;
          this.destinationPath = destinationPath;
          this.destinationFileName = destinationFileName;
          this.urlList = new List&lt;string&gt;();
          this.urlFileReader = new URLFileReader();
          this.httpWorker = new HTTPWorker(this.destinationPath);
          this.reportWriter = new ReportWriter(this.destinationPath,this.destinationFileName);
          this.srcreader = new SourceReader(this.reportWriter);
          this.depth = depth;
  
      }
  
         //this is the method
           public void Vmain(){
  
                this.urlFileReader.ReadURL(urlFilePath);
                this.urlList = urlFileReader.geturlList();           
  
                string pageSrc;
  
                  foreach (string requestUrl in urlList)
                  {
                     //do sruff for requestUrl
                     //the progressbar should move as the urlList iterate.
                     //additionally i want the label on the top of progress bar to     display the current "requestUrl"
                     //as the urlList is over i want quit from the progressbar window and come back to Form1. Till the progrss bar is completed Form1 should be disabled for the user.
  
                  }
  
           }
  
  
  
      }
  </code></pre>
  
  <p>Please explain what is happening there and give a working code if you can. Thank you in advance. There were not any perfect answer that worked for me, even though I spent two days for this. I tried with <code>BackgroundWorker</code>and  threads. But no solution found. :(</p>