Thread: TrackwheelClick
View Single Post
Old 08-31-2004, 09:05 AM   #2
Mark Rejhon
Retired BBF Moderator
 
Mark Rejhon's Avatar
 
Join Date: Aug 2004
Location: Ottawa, Ontario, Canada
Model: Bold
Carrier: Rogers
Posts: 4,870
Default

On most platforms in most programming whenever I only want to run an event once and ignore other events of the same kind, I generally use a static variable to set a flag. (or a global variable or a class member variable, if statics are not available or if I need to use the same variable to block all events while one of them is running). I mainly do C/C++, but it's extremely similiar in format in Java too. May need minor tweaks. The important thing here is static so you remember the last state of the variable between execution of events. But this could easily be a class member, as the class members are persistent (like static) between event calls. Or in the worst case scenario, a global variable can be used instead.

Code:
WhateverEventxxx40; xxx41;
xxx123;
   static boolean bEventRunning = FALSE; // Only initialized on first execution

   if xxx40;bEventRunningxxx41;
   xxx123;
      // The event is already running, exit immediately
      return;
   xxx125;
   bEventRunning = TRUE;

   // Do your deed --
   // Put your event code here.

   bEventRunning = FALSE;
xxx125;
__________________
Thanks,
Mark Rejhon
Author of XMPP extension XEP-0301:
www.xmpp.org/extensions/xep-0301.html - specification
www.realjabber.org - open source
Offline