Connecting Tech Pros Worldwide Forums | Help | Site Map

What's the best Timer to use

DaTurk
Guest
 
Posts: n/a
#1: Mar 30 '07
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.


Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
#2: Mar 30 '07

re: What's the best Timer to use


DaTurk,

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

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"DaTurk" <mmagdits@hotmail.comwrote in message
news:1175286093.627035.112120@d57g2000hsg.googlegr oups.com...
Quote:
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.
>

DaTurk
Guest
 
Posts: n/a
#3: Mar 30 '07

re: What's the best Timer to use


On Mar 30, 3:43 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Quote:
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:1175286093.627035.112120@d57g2000hsg.googlegr oups.com...
>
>
>
Quote:
Hi,
>
Quote:
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.

William Stacey [C# MVP]
Guest
 
Posts: n/a
#4: Mar 30 '07

re: What's the best Timer to use


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" <mmagdits@hotmail.comwrote in message
news:1175288281.941616.98370@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:1175286093.627035.112120@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.
|


gshzheng
Guest
 
Posts: n/a
#5: Mar 31 '07

re: What's the best Timer to use


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" <mmagdits@hotmail.com>
??????:1175288281.941616.98370@y80g2000hsf.googleg roups.com...
Quote:
On Mar 30, 3:43 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Quote:
>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:1175286093.627035.112120@d57g2000hsg.googleg roups.com...
>>
>>
>>
Quote:
Hi,
>>
Quote:
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.
>
>

Willy Denoyette [MVP]
Guest
 
Posts: n/a
#6: Mar 31 '07

re: What's the best Timer to use


"gshzheng" <gshzheng@gmail.comwrote in message
news:O7wR$SzcHHA.2332@TK2MSFTNGP04.phx.gbl...
Quote:
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.


John Vottero
Guest
 
Posts: n/a
#7: Mar 31 '07

re: What's the best Timer to use


"William Stacey [C# MVP]" <william.stacey@gmail.comwrote in message
news:uD09gSxcHHA.4260@TK2MSFTNGP02.phx.gbl...
Quote:
>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?


Rad [Visual C# MVP]
Guest
 
Posts: n/a
#8: Mar 31 '07

re: What's the best Timer to use


On 30 Mar 2007 13:21:33 -0700, DaTurk wrote:
Quote:
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
Rad [Visual C# MVP]
Guest
 
Posts: n/a
#9: Mar 31 '07

re: What's the best Timer to use


On 30 Mar 2007 13:21:33 -0700, DaTurk wrote:
Quote:
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
William Stacey [C# MVP]
Guest
 
Posts: n/a
#10: Apr 1 '07

re: What's the best Timer to use


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" <JVottero@mvpsi.comwrote in message
news:uJ$4oz7cHHA.2068@TK2MSFTNGP06.phx.gbl...
| "William Stacey [C# MVP]" <william.stacey@gmail.comwrote in message
| news:uD09gSxcHHA.4260@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?
|
|


Michael D. Ober
Guest
 
Posts: n/a
#11: Apr 1 '07

re: What's the best Timer to use


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]" <william.stacey@gmail.comwrote in message
news:%237tQVbCdHHA.4684@TK2MSFTNGP06.phx.gbl...
Quote:
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" <JVottero@mvpsi.comwrote in message
news:uJ$4oz7cHHA.2068@TK2MSFTNGP06.phx.gbl...
| "William Stacey [C# MVP]" <william.stacey@gmail.comwrote in message
| news:uD09gSxcHHA.4260@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?
|
|
>
>


Closed Thread