title: How can i add a time elapsed progrerss to my backgroundworker dowork event?
body: <p>In top of form1</p>
  
  <pre><code>label5.Text = "00:00:00";
  </code></pre>
  
  <p>In the dowork event</p>
  
  <pre><code>private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
          {
              DirectoryInfo diri = new DirectoryInfo(@"d:\c-sharp");
              WalkDirectoryTree(diri);
          }
  </code></pre>
  
  <p>WalkDirectoryTree method</p>
  
  <pre><code>int tfiles = 0;
          int tdirs = 0;
          void WalkDirectoryTree(System.IO.DirectoryInfo root)
          {
              System.IO.FileInfo[] files = null;
              System.IO.DirectoryInfo[] subDirs = null;
              string[] workerResult = new string[4];
              try
              {
                  files = root.GetFiles("*.cs");
                  tdirs ++;
                  workerResult[1] = root.FullName;
                  workerResult[3] = tdirs.ToString();
                  backgroundWorker1.ReportProgress(0,workerResult);
              }
              catch (UnauthorizedAccessException e)
              {
  
              }
  
              catch (System.IO.DirectoryNotFoundException e)
              {
  
              }
  
              if (files != null)
              {
                  foreach (System.IO.FileInfo fi in files)
                  {
                      tfiles += files.Length;
                      if (files.Length &gt; 0)
                      {
                          try
                          {
                              int Vara = File.ReadAllText(fi.FullName).Contains("Form1") ? 1 : 0;
  
                              if (Vara == 1)
                              {
                                  workerResult[2] = files[0].FullName;
                              }
                          }
                          catch (FileNotFoundException e)
                          {
  
                          }
                      }
                      workerResult[0] = tfiles.ToString();
                      backgroundWorker1.ReportProgress(0, workerResult);
                      Thread.Sleep(10);
                  }
                  subDirs = root.GetDirectories();
                  foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                  {
                      WalkDirectoryTree(dirInfo);
                  }
              }
          }
  </code></pre>
  
  <p>In the constructor i start the backgroundworker</p>
  
  <pre><code>InitializeComponent();
  
              label1.Visible = false;
              label2.Visible = false;
              label3.Visible = false;
              label4.Visible = false;
              label5.Text = "00:00:00";
              pbt.Size = new Size(984, 23);
              pbt.Location = new Point(12, 358);
              this.Controls.Add(pbt);
  
              backgroundWorker1.WorkerReportsProgress = true;
              backgroundWorker1.RunWorkerAsync();
  </code></pre>
  
  <p>I want to make that once the backgroundworker start the whole process start in the dowork event report to label5 the time elapsed.</p>
  
  <p>First how can i do it ? and should i use a timer or stopwatch ?</p>