timer too slow... why?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.csharp.

Post a new message to this list...

Diego_Atos
I've create a "stupid" animation. A simple label that bounce on borders
of my form. Motion is ruled by a timer that set the timing of every
steps.

If I set the interval at "1000" it works properly, howevery if i set it
at "10" or less, it warks slower than it would be.

Anyone can help me?

Excuse my bad english

Thanks
--
-Diego (Atos)-
-L'uomo è superiore agli animali-
-Fanno eccezione il nano e la giraffa-
-A.Bergonzoni-
-Per rispondere in privato potare "POTA" dall'indirizzo-
Reply to this message...
 
    
George Neuner
On Sat, 11 Sep 2004 12:11:00 GMT, Diego_Atos
<Click here to reveal e-mail address> wrote:

[Original message clipped]

The timer is accurate only to 1/18 of a second (about 55 ms) - trying
to set it lower is useless. This limitation is specified in the docs
for the timer class. Non managed timers have the same limitation -
they are all run from the system heartbeat clock.

For fine animation you have to use multimedia timers or, as some
others have suggested, a separate thread.

George
--
for email reply remove "/" from address
Reply to this message...
 
    
Diego_Atos
Risposta a:
George Neuner (gneuner2/@comcast.net)
_________________
[Original message clipped]

thanks
--
-Diego (Atos)-
-L'uomo è superiore agli animali-
-Fanno eccezione il nano e la giraffa-
-A.Bergonzoni-
-Per rispondere in privato potare "POTA" dall'indirizzo-
Reply to this message...
 
    
Morten Wennevik
Hi Diego,

The timer event is not guaranteed to execute. If your program is busy the timer event might not get time to execute before another timer event is sent. The first waiting event is then cancelled. In effect setting timer to 10 might not seem any faster than setting it to 100.

Dropped timer event is affected by your processor speed, how busy your program is, and how long it takes to execute the timer event code.

--
Happy coding!
Morten Wennevik [C# MVP]
Reply to this message...
 
    
Diego_Atos
Risposta a:
Morten Wennevik (Click here to reveal e-mail address)
_________________
[Original message clipped]

i know this, but how can i really set the speed of my motion?
--
-Diego (Atos)-
-L'uomo è superiore agli animali-
-Fanno eccezione il nano e la giraffa-
-A.Bergonzoni-
-Per rispondere in privato potare "POTA" dall'indirizzo-
Reply to this message...
 
    
Niki Estner
"Diego_Atos" <Click here to reveal e-mail address> wrote in
news:Click here to reveal e-mail address...
[Original message clipped]

speed = distance / time

If you can't lower the time, increase the distance.

The human eye isn't capable of recognizing more than about 25 images per
second, so a timer setting of about 40 is well enough.

Move your label by a greater distance per timer tick.

Niki

Reply to this message...
 
    
Diego_Atos
Risposta a:
Niki Estner (Click here to reveal e-mail address)
_________________

[Original message clipped]

increasing the distance makes a non fluid animation.
the label would jump from a point to another.

Ciao
--
-Diego (Atos)-
-L'uomo è superiore agli animali-
-Fanno eccezione il nano e la giraffa-
-A.Bergonzoni-
-Per rispondere in privato potare "POTA" dall'indirizzo-
Reply to this message...
 
    
Niki Estner
"Diego_Atos" <Click here to reveal e-mail address> wrote in
news:Click here to reveal e-mail address...
[Original message clipped]

Did you measure how much time elapses between two ticks?
Do you use that time as a factor in your motion equation?

Niki

Reply to this message...
 
    
Diego_Atos
Risposta a:
Niki Estner (Click here to reveal e-mail address)
_________________

[Original message clipped]

yes. if i set it at, for exemple, 6000, elapsed time is correct (6 secs)
less than 100 it doesn't work properly. It's a process priority problem,
that a cannot solve.

[Original message clipped]

yes. Every tick, i increase the coordinates

--
-Diego (Atos)-
-L'uomo è superiore agli animali-
-Fanno eccezione il nano e la giraffa-
-A.Bergonzoni-
-Per rispondere in privato potare "POTA" dall'indirizzo-
Reply to this message...
 
    
Niki Estner
"Diego_Atos" <Click here to reveal e-mail address> wrote in
news:Click here to reveal e-mail address...
[Original message clipped]

That's a misunderstanding about how it's supposed to work. The elapsed time
you specify is the *minimum* time.

[Original message clipped]

That is, do you have a formula like this (pseudocode):

Position += speed * (CurrentTime - OldTime);
OldTime = CurrentTime;

Also, if I got you, you're moving a Windows.Forms - Label control? Do you
ensure it gets redrawn immediately? Changing the position does not
neccessarily redraw it that instant.

Usually 50-100 ms is enough for a fluid animation, however if you find you
really need higher frame rates, consider running a loop instead of using
timers at all; This will burn CPU power, but it'll be as fast as it gets.

Niki

Reply to this message...
 
    
Morten Wennevik
On Sat, 11 Sep 2004 14:25:52 GMT, Diego_Atos <Click here to reveal e-mail address> wrote:

[Original message clipped]

Maybe do the animation in a separate thread, or animate according to time span between last "frame" and current time.

--
Happy coding!
Morten Wennevik [C# MVP]
Reply to this message...
 
    
Richard Blewett
If you are doing "real" animation then you may be better off using DirectX
(it has a managed wrapper) rather than a timer.

The problem with timer events from a synchronized System.Timers.Timer is
that if the UI thread is busy doing something else (processing another
event) then the timer cannot execute its callback on the UI thread and
eventually, if the UI thread is very busy, you'll end up with a whole slew
of callbacks queued so when teh UI thread becomes free you will get a sudden
rush of activity. In other words the motion of your animation will be very
jerky.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

"Morten Wennevik" <Click here to reveal e-mail address> wrote in message
news:opsd53ffxaklbvpo@stone...
[Original message clipped]

Reply to this message...
 
    
Richard Blewett
Which timer class are you using?
System.WIndows.Forms.Timer
System.Threading.Timer
System.Timers.Timer

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

"Diego_Atos" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Diego_Atos
Risposta a:
Richard Blewett (Click here to reveal e-mail address)
_________________
[Original message clipped]

this
--
-Diego (Atos)-
-L'uomo è superiore agli animali-
-Fanno eccezione il nano e la giraffa-
-A.Bergonzoni-
-Per rispondere in privato potare "POTA" dall'indirizzo-
Reply to this message...
 
 
System.Threading.Timer
System.Timers.Timer




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com