Drag & Drop & Timer

L

Lloyd Dupont

When doing a Drag & Drop SWF.Timer don't seem to work anymore.
What can I do in such case?

For now, as the OnDragOver event seems to be fire repetitively I use it.
But I cannot control the time interval.

Any better idea?
 
G

Guest

Lloyd Dupont said:
When doing a Drag & Drop SWF.Timer don't seem to work anymore.
What can I do in such case?

For now, as the OnDragOver event seems to be fire repetitively I use it.
But I cannot control the time interval.

As you've discovered, the SWF.Timer is not what you need in this case. As
stated on MSDN: "If you're looking for a metronome, you've come to the wrong
place. The timer events raised by this timer class are synchronous with
respect to the rest of the code in your Windows Forms app."

Instead you should consider using the System.Threading.Timer, as it will
produce the steady drumbeat you need, even during drag & drop. However, the
timer callbacks occur in a separate thread, so you need to take proper care
when accessing any UI controls from your timer callback (use control.Invoke).

Here's an excellent article on the three timers available in .NET:

http://msdn.microsoft.com/msdnmag/issues/04/02/TimersinNET/
 
S

Stoitcho Goutsev \(100\)

The reason WF timer is based on windows messages that comes throught the
message queue. While D&D COM enters a modal loop and the application doesn't
process posted messages until the user is doen with the D&D operation, thus
the application stop registering timer's ticks. Nevertheless WF timers are
so incurate that you should always check with the system time.

If you need the timer working during D&D use some of the others timers that
the framework provides. Keep in mind thought that System.Timers.Timer can be
set to execute its Elapsed event in the main UI thread. If you use this
feature you'll run in the same situations as with the WF timer because the
thread switching is implemented using the message queue.
 
L

Lloyd Dupont

I know about System.Threading.Timer but it is rather akward to use in GUI
code.... :-(
Well I don't really need a metronome, I just want to have a little animation
on the drop target...
I think I will stick to my implementation.

But thanks for your feedbacks! ;-)

--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top