I have a loop that continuously run a function based on some condition.
Now, I want to call that function every 10 minutes only within the loop.
I am using Visual Studio 2005. My code is:
while (boolValue == false)
{
Application.DoEvents();
StartAction(); //i want to call this function for every 10 minutes only
}
I am using the System.Timers, but it’s not calling the function. I don’t know what’s wrong.
My code is:
public static System.Timers.Timer aTimer;
while (boolValue == false)
{
aTimer = new System.Timers.Timer(50000);
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.AutoReset = false;
aTimer.Enabled = true;
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
Application.DoEvents();
StartAction();
}
Why not just use a timer. Have it trigger every ten minutes.
The example in the more specific version is a pretty good example actually
UPDATE
In your updated code, I would change it to this:
I do not see a reason to have a while loop. My guess is that the while loop is not being triggered at all. Also, you should probably set the AutoReset to true so this does run continuously.