473,383 Members | 1,896 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,383 software developers and data experts.

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 12686
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.com

"DaTurk" <mm******@hotmail.comwrote in message
news:11**********************@d57g2000hsg.googlegr oups.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.guard.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.com

"DaTurk" <mmagd...@hotmail.comwrote in message

news:11**********************@d57g2000hsg.googlegr oups.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.threading.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******@hotmail.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...
| On Mar 30, 3:43 pm, "Nicholas Paldino [.NET/C# MVP]"
| <m...@spam.guard.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.com
| >
| "DaTurk" <mmagd...@hotmail.comwrote in message
| >
| news:11**********************@d57g2000hsg.googlegr oups.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.Threading.Timer
2.System.Windows.Forms.Timer
3.System.Timers.Timer

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

System.Threading.Timer is choosed firstly.

gshzheng
20070331

"DaTurk" <mm******@hotmail.com>
??????:11*********************@y80g2000hsf.googleg roups.com...
On Mar 30, 3:43 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.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.com

"DaTurk" <mmagd...@hotmail.comwrote in message

news:11**********************@d57g2000hsg.googleg roups.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**************@TK2MSFTNGP04.phx.gbl...
In the book CLR via C# ,Jeffery Richter,

3 Timers are described in detail.

1.System.Threading.Timer
2.System.Windows.Forms.Timer
3.System.Timers.Timer

System.Threading.Timer uses a thread getting form ThreadPool.
System.Windows.Forms.Timer works with WM_TIMER message.
System.Timers.Timer may be seen as a encapsulation of System.Threading.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.Timer and use System.Threading.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**************@TK2MSFTNGP02.phx.gbl...
>I always use system.threading.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.threading.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.threading.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**************@TK2MSFTNGP06.phx.gbl...
| "William Stacey [C# MVP]" <wi************@gmail.comwrote in message
| news:uD**************@TK2MSFTNGP02.phx.gbl...
| >I always use system.threading.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
The 49 day issue is that a 32 bit millisecond counter overflows and wraps to
zero every 49.7 days. Apparently the .Net 1.x is broken in this regards,
despite the fact the MS fixed it in the underlying OS years earlier. I
haven't heard of any problems in .Net 2.0.

Mike Ober.

"William Stacey [C# MVP]" <wi************@gmail.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
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**************@TK2MSFTNGP06.phx.gbl...
| "William Stacey [C# MVP]" <wi************@gmail.comwrote in message
| news:uD**************@TK2MSFTNGP02.phx.gbl...
| >I always use system.threading.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 #11

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

Similar topics

1
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...
4
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...
5
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
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
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...
5
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,...
4
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...
1
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...
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.