Suppose, I need to perform a resource intensive task with the movement of scroll-bar.
private void hScrollBar_ValueChanged(object sender, EventArgs e)
{
ReCalculate();
}
void ReCalculate()
{
try
{
int n = hScrollBar1.Value;
int f0 = hScrollBar2.Value;
int theta = hScrollBar3.Value;
int a = hScrollBar4.Value;
//... resource-intensive task which uses scroll-bar's values.
}
catch
{
}
}
The problem I am facing is, the event-handler gets executed with the slightest change of the scroll-bar.
I need to block the execution of event-handler until the mouse is released.
So, I tried using mouse-enter and mouse-leave event-handlers like:
bool ready = false;
private void hScrollBars_MouseEnter(object sender, EventArgs e)
{
ready = false;
}
private void hScrollBars_MouseLeave(object sender, EventArgs e)
{
ready = true;
}
along with a checking like:
void ReCalculate()
{
if(ready)
{
try
{
int n = hScrollBar1.Value;
int f0 = hScrollBar2.Value;
int theta = hScrollBar3.Value;
int a = hScrollBar4.Value;
//... resource-intensive task which uses scroll-bar's values.
}
catch
{
}
}
}
But, it doesn't work.
How can I do that?