473,725 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's the best Timer to use

Hi,

I'm creating an application that will need to use a timer to do a
static method call every second. My question, is what would be the
best timer to use? I know there are several, but I'd like to use a
timer that is probably the most reliable, and hopefully designed with
high performance in mind. Thank you in advance.

Mar 30 '07 #1
10 12712
DaTurk,

What you want is the Timer class in the System.Timers class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"DaTurk" <mm******@hotma il.comwrote in message
news:11******** **************@ d57g2000hsg.goo glegroups.com.. .
Hi,

I'm creating an application that will need to use a timer to do a
static method call every second. My question, is what would be the
best timer to use? I know there are several, but I'd like to use a
timer that is probably the most reliable, and hopefully designed with
high performance in mind. Thank you in advance.

Mar 30 '07 #2
On Mar 30, 3:43 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
DaTurk,

What you want is the Timer class in the System.Timers class.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard .caspershouse.c om

"DaTurk" <mmagd...@hotma il.comwrote in message

news:11******** **************@ d57g2000hsg.goo glegroups.com.. .
Hi,
I'm creating an application that will need to use a timer to do a
static method call every second. My question, is what would be the
best timer to use? I know there are several, but I'd like to use a
timer that is probably the most reliable, and hopefully designed with
high performance in mind. Thank you in advance.- Hide quoted text -

- Show quoted text -
Would System.Timer be the best choice? I need the most reliable, and
high performance.

Mar 30 '07 #3
I always use system.threadin g.timer with good luck. I create a new timer
each time to head off a few issues (i.e. 49 day issue, and overlapped jobs).

public void DoIt()
{
Timer t = null;
t = new Timer(
delegate(object state)
{
t.Dispose(); // t is "captured", so we don't need to hold it
elsewhere.

// Run your stuff.

DoIt();
}, null, 1000, -1));
}

Looks like stack recursion, but is not as we start async timer and return.
We schedule a new timer each time and only after we run the work so we don't
have danger of overlapped jobs. However, the next job only starts after the
previous one is finished, so that could be more then 1 second. You can
wiggle the ms's as needed.

--
William Stacey [C# MVP]
PCR concurrency library: www.codeplex.com/pcr
PSH Scripts Project www.codeplex.com/psobject
"DaTurk" <mm******@hotma il.comwrote in message
news:11******** *************@y 80g2000hsf.goog legroups.com...
| On Mar 30, 3:43 pm, "Nicholas Paldino [.NET/C# MVP]"
| <m...@spam.guar d.caspershouse. comwrote:
| DaTurk,
| >
| What you want is the Timer class in the System.Timers class.
| >
| Hope this helps.
| >
| --
| - Nicholas Paldino [.NET/C# MVP]
| - m...@spam.guard .caspershouse.c om
| >
| "DaTurk" <mmagd...@hotma il.comwrote in message
| >
| news:11******** **************@ d57g2000hsg.goo glegroups.com.. .
| >
| >
| >
| Hi,
| >
| I'm creating an application that will need to use a timer to do a
| static method call every second. My question, is what would be the
| best timer to use? I know there are several, but I'd like to use a
| timer that is probably the most reliable, and hopefully designed with
| high performance in mind. Thank you in advance.- Hide quoted text -
| >
| - Show quoted text -
|
| Would System.Timer be the best choice? I need the most reliable, and
| high performance.
|
Mar 30 '07 #4
In the book CLR via C# ,Jeffery Richter,

3 Timers are described in detail.

1.System.Thread ing.Timer
2.System.Window s.Forms.Timer
3.System.Timers .Timer

System.Threadin g.Timer uses a thread getting form ThreadPool.
System.Windows. Forms.Timer works with WM_TIMER message.
System.Timers.T imer may be seen as a encapsulation of System.Threadin g.Timer
..
And Jeffery Richter suggested us NOT to use this cause it possiblly be
remove form FCL.

System.Threadin g.Timer is choosed firstly.

gshzheng
20070331

"DaTurk" <mm******@hotma il.com>
??????:11****** *************** @y80g2000hsf.go oglegroups.com. ..
On Mar 30, 3:43 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
>DaTurk,

What you want is the Timer class in the System.Timers class.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard .caspershouse.c om

"DaTurk" <mmagd...@hotma il.comwrote in message

news:11******* *************** @d57g2000hsg.go oglegroups.com. ..
Hi,
I'm creating an application that will need to use a timer to do a
static method call every second. My question, is what would be the
best timer to use? I know there are several, but I'd like to use a
timer that is probably the most reliable, and hopefully designed with
high performance in mind. Thank you in advance.- Hide quoted text -

- Show quoted text -

Would System.Timer be the best choice? I need the most reliable, and
high performance.


Mar 31 '07 #5
"gshzheng" <gs******@gmail .comwrote in message
news:O7******** ******@TK2MSFTN GP04.phx.gbl...
In the book CLR via C# ,Jeffery Richter,

3 Timers are described in detail.

1.System.Thread ing.Timer
2.System.Window s.Forms.Timer
3.System.Timers .Timer

System.Threadin g.Timer uses a thread getting form ThreadPool.
System.Windows. Forms.Timer works with WM_TIMER message.
System.Timers.T imer may be seen as a encapsulation of System.Threadin g.Timer .
And Jeffery Richter suggested us NOT to use this cause it possiblly be remove form FCL.
While it's true that you better ignore System.Timers.T imer and use System.Threadin g.Timer
instead, no-one ever said that the former would go away any time soon.

Willy.
Mar 31 '07 #6
"William Stacey [C# MVP]" <wi************ @gmail.comwrote in message
news:uD******** ******@TK2MSFTN GP02.phx.gbl...
>I always use system.threadin g.timer with good luck. I create a new timer
each time to head off a few issues (i.e. 49 day issue, and overlapped
jobs).
What is the 49 day issue?
Mar 31 '07 #7
On 30 Mar 2007 13:21:33 -0700, DaTurk wrote:
Hi,

I'm creating an application that will need to use a timer to do a
static method call every second. My question, is what would be the
best timer to use? I know there are several, but I'd like to use a
timer that is probably the most reliable, and hopefully designed with
high performance in mind. Thank you in advance.
I've had very good reliability with system.threadin g.timer. I've used it in
a couple of windows services and it has been very reliable
--
Bits.Bytes
http://bytes.thinkersroom.com
Mar 31 '07 #8
On 30 Mar 2007 13:21:33 -0700, DaTurk wrote:
Hi,

I'm creating an application that will need to use a timer to do a
static method call every second. My question, is what would be the
best timer to use? I know there are several, but I'd like to use a
timer that is probably the most reliable, and hopefully designed with
high performance in mind. Thank you in advance.
I've had very good reliability with system.threadin g.timer. I've used it in
a couple of windows services and it has been very reliable
--
Bits.Bytes
http://bytes.thinkersroom.com
Mar 31 '07 #9
Reaching from memory, but I have read issues people had where the timer
overflows and stops working after 49 days if recurring timer and 1 sec
interval.

--
William Stacey [C# MVP]
"John Vottero" <JV******@mvpsi .comwrote in message
news:uJ******** ******@TK2MSFTN GP06.phx.gbl...
| "William Stacey [C# MVP]" <wi************ @gmail.comwrote in message
| news:uD******** ******@TK2MSFTN GP02.phx.gbl...
| >I always use system.threadin g.timer with good luck. I create a new timer
| each time to head off a few issues (i.e. 49 day issue, and overlapped
| jobs).
|
| What is the 49 day issue?
|
|
Apr 1 '07 #10

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

Similar topics

1
1325
by: Mr Grunge of Gunk Hall. | last post by:
I have an application that listens on a socket using TcpListener. Afiter I create the object I use the Start method and then I wait for an incoming request. No problem with this. When waiting for a socket connection the application is in blocking mode. I can use the Pending method to see if there are incoming requests before calling AcceptSocket. But that's not what I want to do as it means my app can spin around in a frantic loop. I could...
4
2885
by: MLH | last post by:
Best way to make Access 2.0 code wait 10 seconds before processing the next line??? For i=1 to whatever : next i is just too processor intensive. Isn't there something less taxing I can use???
5
2130
by: Jeroen CEuppens | last post by:
Hi, I want to have a timer that counts how long it takes to draw 2 bitmap files...... I use the compact framework, so I haven't got System.Timers Please help me... Greetz JC
2
9036
by: User | last post by:
Hi, What is the best way to release all resources holded by the Timer (myTimer from class System.Timers.Timer)? Is it: 1- myTimer.dispose 2- myTimer.enabled = false 3- myTimer.close
4
3685
by: John Salerno | last post by:
My code is below. The main focus would be on the OnStart method. I want to make sure that a positive integer is entered in the input box. At first I tried an if/else clause, then switched to try/except. Neither is perfect yet, but I was wondering which I should try for in the first place. I figure I need to check for an emptry string, non-numeric strings (maybe these are the same check), 0 and negative numbers (which might also fall into...
5
1588
by: shawncraig | last post by:
Since the ShowDialog() doesn't allow the frmGreyOut finish loading. The cool greyed out effect is never seen. Just the popup called frmYesNo Private Sub frmGreyOut_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load My.Forms.frmYesNo.Message = pstrMessage My.Forms.frmYesNo.ShowDialog() Me.DialogResult = My.Forms.frmYesNo.DialogResult End Sub
4
1927
by: Boki | last post by:
Hi All, I have a timer, if my data queue Q has data, the timer should start work, if there is no data in Q, the timer should stop. However, there is an event can fire timer to start. Should I add a variable to know how many records inside Q ? Ya, I think so, because timer should use for unknown events, check it in a period.
1
1618
by: truedecembr | last post by:
Hi everyone, I am brand new to Java and not really even sure what I'm doing... I'm supposed to be writing a Timer class that is part of a stop watch application, and it seems to me that the program is correct, but when I run the tester, it is obviously not. The goal is to enter a base and a time, and find time % base, then tell how many times it cycled back to zero. I don't know what is wrong with my program, because it appears to me that it...
1
2619
by: Robin Becker | last post by:
I've just been testing out Jakob Sievers' speedup of Python 2.5.2 by compiling on freebsd with gcc-4.3.3 (the standard freebsd 6.1 gcc is 3.4.4). I'm glad to say that his modification did improve pybench overall by about 12%, but during the testing I noticed that in fact some of the pybench results were much worse using gcc-4.3.3 compared to gcc-3.4.4. Of course it may be that freebsd has put more work into 3.4.4, but when I did a...
0
8888
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
8752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9257
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...
1
9174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9111
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
8096
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...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3221
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
2
2634
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.