I have found with certain event handlers that they may be called recursively (e.g, an onchange handler that changes the item that called the event will call itself again).
I declare something like:
static bool beenHere = false;
I use it as follows
eventHandler() {
static bool beenHere = false;
if(beenHere) {
beenHere = false;
return;
}
beenHere=true;
return;
}