title: In my numericUpDown Changed event im calling a function() and when im changing the numeric value when program is running its getting slower
body: <p>This is the numeric changed event code with timer2 wich didnt solve hte problem the function im calling is DoThresholdCheck()</p>
  
  <p>The problem is that in this function im creating each time im changing the numeric value a temp list each time im moving the numeric value change it the list is been created from the start. The problem is that if im using a big file in my program the list is containing sometimes  16500 indexs and its taking time to loop over the list so i guess when im changing the numeric value its taking time to loop over the list. If im using smaller video file for example the list containing 4000 indexs so there is no problems. I tried to use Timer2 maybe i could wait 0.5 seconds between each time the numeric value is changed but still dosent work good.</p>
  
  <p>When im changing the numeric value while the program is running on a big video file its taking the values to be changed like 1-2 seconds ! thats a lot of time.</p>
  
  <p>Any way to solve it ? Maybe somehow to read the list loop over the list faster even if the list is big ?</p>
  
  <pre><code>private void numericUpDown1_ValueChanged(object sender, EventArgs e)
          {
              Options_DB.Set_numericUpDownValue(numericUpDown1.Value);
              if (isNumericChanged == true)
              {
                  isNumericChanged = false;
                  myTrackPanelss1.trackBar1.Scroll -= new EventHandler(trackBar1_Scroll);
                  DoThresholdCheck();
                  counter = 0;
              }
          }
  
          private void timer2_Tick(object sender, EventArgs e)
          {
              counter++;
              if (counter &gt; 1)
              {
                  isNumericChanged = true;
                  //timer2.Stop();
              }
          }
  </code></pre>
  
  <p>This is the DoThresholdChecks() function code:</p>
  
  <pre><code>private void DoThresholdCheck()
          {
              List&lt;string&gt; fts;
              //const string D6 = "000{0}.bmp";
              if (Directory.Exists(subDirectoryName))
              {
  
  
  
                  if (!File.Exists(subDirectoryName + "\\" + averagesListTextFile + ".txt"))
                  {
                      return;
                  }
                  else
                  {
  
  
  
                      bool trackbarTrueFalse = false ;
  
                          fts = new List&lt;string&gt;();
                          int counter = 0;
                          double thershold = (double)numericUpDown1.Value;
                          double max_min_threshold = (thershold / 100) * (max - min) + min;
                          //label13.Text = max_min_threshold.ToString();
                          _fi = new DirectoryInfo(subDirectoryName).GetFiles("*.bmp");
  
  
                          for (int i = 0; i &lt; myNumbers.Count; i++)
                          {
                              if (myNumbers[i] &gt;= max_min_threshold)
                              {
                                  //f.Add(i);
                                  string t = i.ToString("D6") + ".bmp";
                                  if (File.Exists(subDirectoryName + "\\" + t))
                                  {
                                      counter++;
                                      button1.Enabled = false;
                                      myTrackPanelss1.trackBar1.Enabled = true;
                                      trackbarTrueFalse = true;
                                      label9.Visible = true;
                                     // myTrackPanelss1.trackBar1.Scroll += new EventHandler(trackBar1_Scroll);
                                      //myTrackPanelss1.trackBar1.Minimum = 0;
                                     // myTrackPanelss1.trackBar1.Maximum = f.Count;
                                     // myTrackPanelss1.trackBar1.Value = f.Count;
                                     // myFiles = new Bitmap(myTrackPanelss1.trackBar1.Value);
  
  
  
                                  }
                                  else
                                  {
                                      label9.Visible = false;
                                      trackbarTrueFalse = false;
                                      button1.Enabled = true;
                                      myTrackPanelss1.trackBar1.Enabled = false;
                                      myTrackPanelss1.trackBar1.Value = 0;
                                      pictureBox1.Image = Properties.Resources.Weather_Michmoret;
                                      label5.Visible = true;
                                      secondPass = true;
                                      break;
                                  }
  
                                  //fts.Add(string.Format(D6, myNumbers[i]));
                              }
                          }
  
                          //myTrackPanelss1.trackBar1.Maximum = _fi.Length - 1;
                          if (myTrackPanelss1.trackBar1.Maximum &gt; 0)
                          {
                              if (trackbarTrueFalse == false)
                              {
                                  myTrackPanelss1.trackBar1.Value = 0;
                              }
                              else
                              {
                                  myTrackPanelss1.trackBar1.Maximum = counter;
                                  myTrackPanelss1.trackBar1.Value = 0;
                                  SetPicture(0);
                                  myTrackPanelss1.trackBar1.Scroll += new EventHandler(trackBar1_Scroll);
                              }
                              //checkBox2.Enabled = true;
                          }
                          if (_fi.Length &gt;= 0)
                          {
                              label15.Text = _fi.Length.ToString();
                              label15.Visible = true;
                          }
  }
              }
              else
              {
                  button1.Enabled = true;
              }
  }
  </code></pre>