title: how to show filecount on UI in windows application
body: <p>what I am trying to do is to update the file count on UI every time it reads the file. Similarly it is not even showing the total number of files on the UI , the moment user clicks on the ok button of the browseFolder event.Any help would be appreciated. Below Is my Code :</p>
  
  <pre><code>private void browse_Click(object sender, EventArgs e)
      {
          try
          {
              int fileCount = 0;
              string newFileName1 = "";
              string newFileName2 = "";
              week = textBox2.Text;
              if (week == null || week == "")
              {
                  MessageBox.Show("Week cannot be null.");
                  return;
              }
  
  
              DialogResult result = folderBrowserDialog1.ShowDialog();
  
              if (result == DialogResult.OK)
              {
                  int j = 0;
                  int totalNoOfFiles = 0;
                  DateTime starttime = DateTime.Now;
  
                  string folderPath = folderBrowserDialog1.SelectedPath;
                  string folderName = Path.GetFileName(folderBrowserDialog1.SelectedPath);
  
                  totalNoOfFiles = Directory.GetFiles(folderPath, "*.txt", SearchOption.AllDirectories).Length;
                  lbltotalfiles.Text = Convert.ToString(totalNoOfFiles);
                  progressBar1.Minimum = 0;
                  progressBar1.Maximum = totalNoOfFiles;
  
                  DirectoryInfo dInfo = new DirectoryInfo(folderPath);
  
                  foreach (DirectoryInfo folder in dInfo.GetDirectories())
                  {
                      newFileName1 = "Files_with_dates_mismatching_the_respective_week_" + folder.Name + ".txt";
                      newFileName2 = "Files_with_wrong_date_format_" + folder.Name + ".txt";
  
                      if (File.Exists(folderPath + "/" + newFileName1))
                      {
                          File.Delete(folderPath + "/" + newFileName1);
                      }
  
                      if (File.Exists(folderPath + "/" + newFileName2))
                      {
                          File.Delete(folderPath + "/" + newFileName2);
                      }
  
                      FileInfo[] folderFiles = folder.GetFiles();
  
                      if (folderFiles.Length != 0)
                      {
                          List&lt;Task&gt; tasks = new List&lt;Task&gt;();
                          foreach (var file in folderFiles)
                          {
                              fileCount = ++fileCount;
                              lblFilesRead.Text = Convert.ToString(fileCount);
                              progressBar1.Value = ++j;
                              var task = ReadFile(file.FullName, folderPath, folder.Name, week);
                              tasks.Add(task);
                          }
  
                          Task.WhenAll(tasks.ToArray());
                          DateTime stoptime = DateTime.Now;
                          TimeSpan totaltime = stoptime.Subtract(starttime);
                          label6.Text = Convert.ToString(totaltime);
                          textBox1.Text = folderPath;
  
                      }
                  }
                  DialogResult result2 = MessageBox.Show("Read the files successfully.", "Important message", MessageBoxButtons.OK, MessageBoxIcon.Information);
              }
          }
          catch (Exception)
          {
  
              throw;
          }
      }
  </code></pre>