473,604 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

timer control

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 event I update a label on my form,
nothing else. just counting in my head I have determined that it take
roughly 14 seconds to get through 1000 ticks or 1 second of the timer.

This really surprises me. I haven't even done any processing yet and the
thing is already slow. Is this typical of this control?

If I wanted to have a loop with time based execution, what is the
appropriate method? This is a windows form app and the emulator is running
in a dialog.

Thanks for any suggestions,
Steve
Dec 15 '05 #1
6 2212
Howdy,

I would skip the windows API because you are going to get that slowness
running in a dialog.
I've noticed that nothing under 20ms in a timer is really accurate
either.

Maybe directX would be better for an emulator?

Otherwise, why not just put your code in a while loop with a sleep
statement?

Steven Nagy

Dec 15 '05 #2

"Steve" <ss*@sss.com> wrote in message
news:u9******** ******@TK2MSFTN GP11.phx.gbl...
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 event I update a label on my
form, nothing else. just counting in my head I have determined that it
take roughly 14 seconds to get through 1000 ticks or 1 second of the timer.

This really surprises me. I haven't even done any processing yet and the
thing is already slow. Is this typical of this control?

If I wanted to have a loop with time based execution, what is the
appropriate method? This is a windows form app and the emulator is
running in a dialog.

Thanks for any suggestions,
Steve


No, it doesn't run way slow, the timer interval can't be less than the (HW)
system clock resolution. Some systems have a 10 msec. system clock
resolution while others may have something like 15 msec. That means that a
timer will need at least 10 (or 15) seconds to fire 1000 times. Note that I
said at least, Windows is not a real time OS, so there is no guarantee that
your timer event handler will be called at the exact time the timer fires,
the call may get delayed some undefined time depending on the current
activity of the system
The same goes for Thread.Sleep(n) , don't expect that Sleep(2) will put the
thread asleep for 2 msec., no, it will sleep for at least 10 msec.

Willy.
Dec 16 '05 #3

"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:Op******** *******@TK2MSFT NGP12.phx.gbl.. .

"Steve" <ss*@sss.com> wrote in message
news:u9******** ******@TK2MSFTN GP11.phx.gbl...
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 event I update a label on my
form, nothing else. just counting in my head I have determined that it
take roughly 14 seconds to get through 1000 ticks or 1 second of the
timer.

This really surprises me. I haven't even done any processing yet and the
thing is already slow. Is this typical of this control?

If I wanted to have a loop with time based execution, what is the
appropriate method? This is a windows form app and the emulator is
running in a dialog.

Thanks for any suggestions,
Steve


No, it doesn't run way slow, the timer interval can't be less than the
(HW) system clock resolution. Some systems have a 10 msec. system clock
resolution while others may have something like 15 msec. That means that a
timer will need at least 10 (or 15) seconds to fire 1000 times. Note that
I said at least, Windows is not a real time OS, so there is no guarantee
that your timer event handler will be called at the exact time the timer
fires, the call may get delayed some undefined time depending on the
current activity of the system
The same goes for Thread.Sleep(n) , don't expect that Sleep(2) will put the
thread asleep for 2 msec., no, it will sleep for at least 10 msec.

Willy.


Willy, this makes perfect sense, thanks for the thorough explanation. It
does leave me still with a question, if I don't want to use DirectX like
Steven suggested, how do I implement a time controlled loop?

If the system time has a 10ms resolution (or 15 or whatever), then I can't
count on using that to determine elapsed time. I've never had to do this
before... If yo uhave any suggestions, I would really appreciate them.

Thanks again,
Steve
Dec 16 '05 #4

"Steven Nagy" <le*********@ho tmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Howdy,

I would skip the windows API because you are going to get that slowness
running in a dialog.
I've noticed that nothing under 20ms in a timer is really accurate
either.

Maybe directX would be better for an emulator?

Otherwise, why not just put your code in a while loop with a sleep
statement?

Steven Nagy


Hi,

Thanks for the suggestion. DirectX would be over kill for this and I also
need to use WinForms for the UI. The sleep statement was interesting, but
then I read Willys post where he says it suffers from the same time
resolution as the timer control.

Thanks again,
Steve
Dec 16 '05 #5

"Steve" <ss*@sss.com> wrote in message
news:em******** ******@TK2MSFTN GP11.phx.gbl...

"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:Op******** *******@TK2MSFT NGP12.phx.gbl.. .

"Steve" <ss*@sss.com> wrote in message
news:u9******** ******@TK2MSFTN GP11.phx.gbl...
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 event I update a
label on my form, nothing else. just counting in my head I have
determined that it take roughly 14 seconds to get through 1000 ticks or 1
second of the timer.

This really surprises me. I haven't even done any processing yet and
the thing is already slow. Is this typical of this control?

If I wanted to have a loop with time based execution, what is the
appropriate method? This is a windows form app and the emulator is
running in a dialog.

Thanks for any suggestions,
Steve


No, it doesn't run way slow, the timer interval can't be less than the
(HW) system clock resolution. Some systems have a 10 msec. system clock
resolution while others may have something like 15 msec. That means that
a timer will need at least 10 (or 15) seconds to fire 1000 times. Note
that I said at least, Windows is not a real time OS, so there is no
guarantee that your timer event handler will be called at the exact time
the timer fires, the call may get delayed some undefined time depending
on the current activity of the system
The same goes for Thread.Sleep(n) , don't expect that Sleep(2) will put
the thread asleep for 2 msec., no, it will sleep for at least 10 msec.

Willy.


Willy, this makes perfect sense, thanks for the thorough explanation. It
does leave me still with a question, if I don't want to use DirectX like
Steven suggested, how do I implement a time controlled loop?

If the system time has a 10ms resolution (or 15 or whatever), then I can't
count on using that to determine elapsed time. I've never had to do this
before... If yo uhave any suggestions, I would really appreciate them.

Thanks again,
Steve


Steve,
If you need to fire a timer at an interval that is smaller than say 20 msec.
you are stuck, even DirectX can't help you with that. Could you please
explain what exactly you want to achieve.

Willy.

Dec 16 '05 #6

"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:ew******** ******@TK2MSFTN GP14.phx.gbl...

"Steve" <ss*@sss.com> wrote in message
news:em******** ******@TK2MSFTN GP11.phx.gbl...

"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:Op******** *******@TK2MSFT NGP12.phx.gbl.. .

"Steve" <ss*@sss.com> wrote in message
news:u9******** ******@TK2MSFTN GP11.phx.gbl...
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 event I update a
label on my form, nothing else. just counting in my head I have
determine d that it take roughly 14 seconds to get through 1000 ticks or
1 second of the timer.

This really surprises me. I haven't even done any processing yet and
the thing is already slow. Is this typical of this control?

If I wanted to have a loop with time based execution, what is the
appropriate method? This is a windows form app and the emulator is
running in a dialog.

Thanks for any suggestions,
Steve
No, it doesn't run way slow, the timer interval can't be less than the
(HW) system clock resolution. Some systems have a 10 msec. system clock
resolution while others may have something like 15 msec. That means that
a timer will need at least 10 (or 15) seconds to fire 1000 times. Note
that I said at least, Windows is not a real time OS, so there is no
guarantee that your timer event handler will be called at the exact time
the timer fires, the call may get delayed some undefined time depending
on the current activity of the system
The same goes for Thread.Sleep(n) , don't expect that Sleep(2) will put
the thread asleep for 2 msec., no, it will sleep for at least 10 msec.

Willy.


Willy, this makes perfect sense, thanks for the thorough explanation. It
does leave me still with a question, if I don't want to use DirectX like
Steven suggested, how do I implement a time controlled loop?

If the system time has a 10ms resolution (or 15 or whatever), then I
can't count on using that to determine elapsed time. I've never had to
do this before... If yo uhave any suggestions, I would really appreciate
them.

Thanks again,
Steve


Steve,
If you need to fire a timer at an interval that is smaller than say 20
msec. you are stuck, even DirectX can't help you with that. Could you
please explain what exactly you want to achieve.

Willy.

I'm trying to make a very basic emulator for an embedded device. In
emulating the UI, there are different durations at which things happen.
When I designed the application in my head and on paper, processing tasks
evey millisecond was the cleanest way. I can make it work good enough with
100 ms intervals, I will just have some slight inaccuracies, this is just a
UI emulator, so it's not critical.
Dec 19 '05 #7

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

Similar topics

4
31211
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 http://searchvb.techtarget.com/tip/1,289483,sid8_gci535495,00.html which has the following: > Want to really get down to instants? This tip from reader Phil Lenoir tells you how. >...
3
1862
by: David | last post by:
Hi There! I'm using Timer control to record how long my application perform certain tasks. However, apparently Timer control is not doing its' job (i.e. Not firing Tick event) while my application is busy. So even if my application took 2 mins, the label that is used to show the number of seconds elapsed will still say "2 seconds".
11
2555
by: Steve Jorgensen | last post by:
I've recently been playing with some UI ideas that require the user of a timer to drive animation. The problem I'm having is that Access routinely stops firing timer events for long periods of time. For example, the user types a character in another window, and the timer stops. The user types another key, and the timer starts again, runs for a few seconds, then stops again. Now, the code I'm writing would easily tolerate a few...
5
5082
by: Dhilip Kumar | last post by:
Hi all, I have developed a windows service using the windows service project template in VS.NET. I have used three controls in the service, a timer, performance counter and a message queue control. The service will "sleep" for 'n' seconds using the timer control and whenever the timer_elapsed event occurs, I use the performance counter object to determine availability of few resources. Based on the availability of resources, I use the...
7
2372
by: Noozer | last post by:
I have a timer on a form. It isn't firing at all. I know that the timer is enabled, and that the interval is low (4000, which should be 4 seconds). To ensure the timer wasn't being inadvertantly reset I put some extra code in the subs that enable and disable the timer. They fire as expected. To test this I added a second timer with a 1 second interval. The event for this time would output the enabled status of the first timer and its...
2
10420
by: vinay | last post by:
Hi I must be missing some obvious point, but can someone let me know how do I add a windows.forms.timer control to a form at run time Private TM as new windows.forms.time Dim sForm as for sForm.controls.add(TM) => throwing an error - Value of type 'System.Windows.Forms.Timer' cannot be converted to 'System.Windows.Forms.Control'
7
5988
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it seems recently connections just drop off because the timer stops firing. My question is if there is a timeout in the timer event that just shuts down the call if the timer event is taking too long to complete...?
4
4627
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this program is like so: static void Main() {
4
5712
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have a main thread an another worker thread. The main Thread creates another thread and waits for the threads signal to continue the main thread. Everything works inside a ModalDialog and everyting is secured by Invoke/BeginInvoke, and synchronisation primitves like WaitHandles, Evetns, Semaphores, etc... All works good and with no race conditions or locks. I have a System.Windows.Forms.Timer in the main
3
3860
by: Steve | last post by:
Hi All I am using VB.net 2008 and use timer controls within my applications Question Does the code in a Timer control.tick event run on a different thread to the main Application thread (UI Thread)? In some of the timers I update some UI controls e.g statusbar.labels and I
0
7997
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8409
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8280
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5882
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3907
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1526
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.