Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with Timers...

Status
Not open for further replies.

AtariJag64

Programmer
Mar 4, 2002
8
US
I'm trying to setup a program that will perform a function call on every tick of a timer; however, its not working correctly.

I basically just set up a default timer, with an interval of 2000.

Now I have a function within the timer1_tick() method
{
generate()
}

The function is called correctly on the first tick; however, the next tick, the function is called twice! And the third tick, the function is called 4 times..then 8 times...and so on.. The repetition of the function calls eventually crashes the program.

Does anyone have any idea what could be causing this? I haven't changed any of the parameters on the timer, I'm just using the default setup...other than the interval changed to 2000.

Thanks,
-Chris B.
 
Are you touching any timer-related code in your tick-event? If you do something like add the tick event to the timer's event handler, that would cause this.

0th time - add event handler - tick gets called once
1st time - add event handler - tick now gets called twice
2nd time - add event handler - tick now gets called 4 times
etc.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top