This is the code in the NumericUpDown ValueChanged event:
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
DoThresholdCheck();
}
And this is the DoThresholdCheck() code:
private void DoThresholdCheck()
{
List<int> f;
List<string> fts;
const string D6 = "000{0}.bmp";
if (Directory.Exists(subDirectoryName))
{
if (!File.Exists(subDirectoryName + "\\" + averagesListTextFile + ".txt"))
{
return;
}
else
{
f = new List<int>();
fts = new List<string>();
Bitmap myFiles;
int counter = 0;
double thershold = (double)numericUpDown1.Value;
double max_min_threshold = (thershold / 100) * (max - min) + min;
_fi = new DirectoryInfo(subDirectoryName).GetFiles("*.bmp");
for (int i = 0; i < myNumbers.Count; i++)
{
if (myNumbers[i] >= max_min_threshold)
{
string t = i.ToString("D6") + ".bmp";
if (File.Exists(subDirectoryName + "\\" + t))
{
button1.Enabled = false;
myTrackPanelss1.trackBar1.Enabled = true;
}
else
{
button1.Enabled = true;
myTrackPanelss1.trackBar1.Enabled = false;
pictureBox1.Image = Properties.Resources.Weather_Michmoret;
label5.Visible = true;
break;
}
}
}
if (myTrackPanelss1.trackBar1.Maximum > 0)
{
SetPicture(0);
myTrackPanelss1.trackBar1.Scroll += new EventHandler(trackBar1_Scroll);
}
if (_fi.Length >= 0)
{
label15.Text = _fi.Length.ToString();
label15.Visible = true;
}
}
}
else
{
button1.Enabled = true;
}
}
What I want to do is; each time I change the NumericUpDown value in the program it will call the function in the event. In the event I create a new temp list each time and perform operations and make some checks on that list.
The problem is when I’m changing the NumericUpDown value a few times up and down in the program and then try to use the trackBar1 to move between the images again, the trackbar1 moves very slowly. When initially running the program, the slide bar in the trackbar1 moves quickly and moves quickly between images, but when I change the NumericUpDown values the trackbar moves slowly for some reason.
I tried to add a Timer2 and maybe use it in the NumericUpDown to make it call the function only after 500ms, for example, but it didn’t solve it.
I can’t figure out why its moving so slow.
I’am not shore if it is the problem, but seems you adding event handler
myTrackPanelss1.trackBar1.Scroll += new EventHandler(trackBar1_Scroll);but never removing it. So you always adding event handler and after a wiletrackBar1_Scrollwill be fired many times. Set breakpoint intrackBar1_Scrolland you will see how many times event handler is raised. Solution could be remove event handler or add it just one time.