Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to catch a repeated 500ms Form_Timer event while dragging the mouse. i.e. between mouse down and mouse up events. The Timer event is firing outside of the drag but not inside.

The reason for the Timer event is that the program does significant processing during the drag and often does not catch the most recent mouse location - after catching the timer event the program can poll the current mouse position. [For example the user may have dragged the mouse quickly into a position which is not reported by MouseMove and then hold the drag there]

Has anyone else had or resolved this problem?

I have experienced it on Windows XP Pro SP3 and Windows 7 Starter.

share|improve this question

This is because all events in the GUI run on a single "Event Dispatch Thread", and the mouse handling events of dragging cause the timer to be queued. The events are actually Window Messages and the message handlers have to be called from a single thread. Mouse dragging keeps the event thread "busy", so it can't run any other window procedures while dragging is occurring. This is one of the design limitations of the original native Windows GUIs, of which Access 2003 is one such program that uses it.

Input handling and the threading model were improved in newer versions of Windows and with different frameworks, such as that used in Office 2010. Not sure if it resolves your problem, but it might help to try a new version of Office.

Another thing you can try is running a busy loop that calls DoEvents every so often to process the window messages, and just use sleeps to time the 500 ms interrupts rather than having the system call your event every 500 ms.

share|improve this answer
DoEvents will work, but there is a tradeoff: loops without it will execute quicker by an order of magnitude. If all you are doing is providing user information (e.g. a progress bar), then DoEvents every 10th iteration (etc etc) may be a better choice. – horatio Oct 24 '12 at 21:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .