473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

timer too slow... why?

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-
Nov 16 '05 #1
13 9670
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" <di********@POTAbigfoot.com> wrote in message
news:MP************************@news.tin.it...
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-

Nov 16 '05 #2
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]
Nov 16 '05 #3
Risposta a:
Richard Blewett (ri*****@dotnetconsult.co.uk)
_________________
System.Timers.Timer


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-
Nov 16 '05 #4
Risposta a:
Morten Wennevik (Mo************@hotmail.com)
_________________
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.


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-
Nov 16 '05 #5
On Sat, 11 Sep 2004 14:25:52 GMT, Diego_Atos <di********@POTAbigfoot.com> wrote:
Risposta a:
Morten Wennevik (Mo************@hotmail.com)
_________________
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.


i know this, but how can i really set the speed of my motion?


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]
Nov 16 '05 #6
"Diego_Atos" <di********@POTAbigfoot.com> wrote in
news:MP************************@news.tin.it...
Risposta a:
Morten Wennevik (Mo************@hotmail.com)
_________________
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.


i know this, but how can i really set the speed of my motion?


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
Nov 16 '05 #7
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" <Mo************@hotmail.com> wrote in message
news:opsd53ffxaklbvpo@stone...
On Sat, 11 Sep 2004 14:25:52 GMT, Diego_Atos <di********@POTAbigfoot.com>
wrote:
Risposta a:
Morten Wennevik (Mo************@hotmail.com)
_________________
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.


i know this, but how can i really set the speed of my motion?


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]

Nov 16 '05 #8
Risposta a:
Niki Estner (ni*********@cube.net)
_________________
Move your label by a greater distance per timer tick.


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-
Nov 16 '05 #9
"Diego_Atos" <di********@POTAbigfoot.com> wrote in
news:MP************************@news.tin.it...
Risposta a:
Niki Estner (ni*********@cube.net)
_________________
Move your label by a greater distance per timer tick.


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


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

Niki
Nov 16 '05 #10
Risposta a:
Niki Estner (ni*********@cube.net)
_________________

Did you measure how much time elapses between two ticks?
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.
Do you use that time as a factor in your motion equation?


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-
Nov 16 '05 #11
"Diego_Atos" <di********@POTAbigfoot.com> wrote in
news:MP************************@news.tin.it...
Risposta a:
Niki Estner (ni*********@cube.net)
_________________

Did you measure how much time elapses between two ticks?


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.


That's a misunderstanding about how it's supposed to work. The elapsed time
you specify is the *minimum* time.
Do you use that time as a factor in your motion equation?


yes. Every tick, i increase the coordinates


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
Nov 16 '05 #12
On Sat, 11 Sep 2004 12:11:00 GMT, Diego_Atos
<di********@POTAbigfoot.com> wrote:
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.


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
Nov 16 '05 #13
Risposta a:
George Neuner (gneuner2/@comcast.net)
_________________

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


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-
Nov 16 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: William Bub | last post by:
Is there an accurate way to create a "stopwatch" good to 1/10 of a second? I'm not sure if I should use the timer control, or some way to access the computer timer. I found the following site...
5
by: Richard P | last post by:
I need some help on timers. My app is asp.net 1.1 website running in a shared hosting environment with a third-party service provider. I currently request and cache 20 - 40 remote RSS feeds. When a...
4
by: Robert W. | last post by:
I'm building a WinForms app that is a companion to a Pocket PC app. The WinForms app initiates a separate thread that calls a Notification window. This window resides in the lower right corner of...
6
by: Steve | last post by:
I am working on a emulator and need to have time based events. I've tried to use the timer control and discovered that it runs waaaaaaay slow. I set the tick frequency to 1, then in the tick...
5
by: Flack | last post by:
Hey guys, Here is what I am trying to achieve: I have a grid, and every once in a while the grid will receive a message to add a new row and highlight it (change the backcolor) for five...
5
by: joec | last post by:
I'm writing an arcade game were I need a delay for the man between steps. Also using the keyboard arrows to direct user man. Using delay at 5000 (changeable) Dim mark(15000) 'Sub DEALAYMAN:...
12
by: Gina_Marano | last post by:
I have created an array of timers (1-n). At first I just created windows form timers but I read that system timers are better for background work. The timers will just be monitoring different...
19
by: colin | last post by:
Hi, Im trying to time some parts of my code using the Stopwatch class, but it is so slow, I tried the QueryPerformanceFrequency() but this seems to be just as slow, if I just simply call this...
7
by: ssecorp | last post by:
I am not clear about the results here. from timeit import Timer import Decorators def fib(n): a, b = 1, 0 while n: a, b, n = b, a+b, n-1
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.