title: Progress bar in foreach function not working
body: <p>The program i am designing makes an image by getting the file name of the image, searches for that name in a cdb and then makes a picture with the data from that database item.All of that works. What i want to do now is add a progress bar because if you're doing for a large amount of pics it can take a while so a progress bar would help keep track of it. Here is the code i am using but the progress in the progress bar does not advance until the end i want to avoid using background worker(if i can).</p>
  
  <pre><code>   private void button5_Click(object sender, EventArgs e)
      {
          if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
          {
              string folder = folderBrowserDialog1.SelectedPath;
              DirectoryInfo dinfo = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
              FileInfo[] Files = dinfo.GetFiles("*.jpg");
              int count = Files.Length;
              int current = 0;
              foreach (FileInfo file in Files)
              {
                  string path = Path.GetFileNameWithoutExtension(file.Name);
                  int cardid = Convert.ToInt32(path);
                  if (Program.CardData.ContainsKey(cardid))
                  {
                      DevPro_CardManager.cardmaker.IMG = LoadBitmap(folderBrowserDialog1.SelectedPath + "//" + file.Name);
                      string lev = Program.CardData[cardid].Level.ToString();
                      comboBox2.SelectedItem = lev;
                      string att = Program.CardData[cardid].Attribute.ToString();
                      if (att == "1")
                      {
                          att = "earth";
                      }
                      else if (att == "2")
                      {
                          att = "water";
                      }
                      else if (att == "4")
                      {
                          att = "fire";
                      }
                      else if (att == "8")
                      {
                          att = "wind";
                      }
                      else if (att == "16")
                      {
                          att = "light";
                      }
                      else if (att == "32")
                      {
                          att = "dark";
                      }
                      else if (att == "64")
                      {
                          att = "divine";
                      }
                      comboBox1.SelectedItem = att;
                      if (Program.CardData[cardid].Atk.ToString() == "-2")
                      {
                          textBox2.Text = "????";
                      }
                      else
                      {
                          textBox2.Text = Program.CardData[cardid].Atk.ToString();
                      }
                      if (Program.CardData[cardid].Def.ToString() == "-2")
                      {
                          textBox1.Text = "????";
                      }
                      else
                      {
                          textBox1.Text = Program.CardData[cardid].Def.ToString();
                      }
                      string ctp = Program.CardData[cardid].Type.ToString();
                      if (ctp == "2" || ctp == "130" || ctp == "65538" || ctp == "131074" || ctp == "262146" || ctp == "524290")
                      {
                          ctp = "spell";
                      }
                      else if (ctp == "4" || ctp == "1048580" || ctp == "131076")
                      {
                          ctp = "trap";
                      }
                      else if (ctp == "129" || ctp == "161")
                      {
                          ctp = "ritual";
                      }
                      else if (ctp == "65" || ctp == "97")
                      {
                          ctp = "fusion";
                      }
                      else if (ctp == "8193" || ctp == "8225" || ctp == "12321")
                      {
                          ctp = "synchro";
                      }
                      else if (ctp == "8388609" || ctp == "8388641")
                      {
                          ctp = "xyz";
                      }
                      else if (ctp == "33" || ctp == "545" || ctp == "1057" || ctp == "2081" || ctp == "4129" || ctp == "4194337")
                      {
                          ctp = "effect";
                      }
                      else if (ctp == "17" || ctp == "4113")
                      {
                          ctp = "normal";
                      }
                      else if (ctp == "16401")
                      {
                          ctp = "token";
                      }
                      comboBox3.SelectedItem = ctp;
                      GenerateCard();
                      ImageResizer.CropImage(361, 523, pictureBox1.Image, @"anime cards\" + Path.GetFileName(file.Name));
                      int cardcount = +1;
                      label8.Text = cardcount.ToString();
                  }      
                  current++;
                  progressBar1.Value = current / count;
              }
          }
      }
  </code></pre>