Re: Brenbot Plugin Error [message #420111 is a reply to message #418329] |
Wed, 17 February 2010 04:26 |
|
danpaul88
Messages: 5795 Registered: June 2004 Location: England
Karma:
|
General (5 Stars) |
|
|
I find a handy solution to that is to do the following;
Initialize a global variable to 0
Every time you start the timer, increment that global variable and then save a COPY of the new value in the session heap
When the timer goes off compare the value of the global variable against the copy in the session heap. If they don't match just abort whatever it is the timer was meant to do because either a second instance of the timer was started or the timer was cancelled.
To cancel the timer simply increment the global variable so it doesn't match the copy in the timers session heap.
This way you avoid duplicate timers trying to do the same thing as each other and also provide a mechanism for cancelling timers.
Depending on how often this timer is going to be created / cancelled you might want to also add a check which resets it to 0 once it reaches 1,000,000 or so to prevent it from causing an overflow error.
[Updated on: Wed, 17 February 2010 04:29] Report message to a moderator
|
|
|