什么是最好的计时器使用 [英] What's the best Timer to use

查看:60
本文介绍了什么是最好的计时器使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在创建一个应用程序,需要使用计时器每秒进行一次

静态方法调用。我的问题是,什么是

最佳定时器?我知道有几个,但我想使用一个可能最可靠的

计时器,并且希望设计具有

的高性能。提前谢谢你。

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,


你想要的是计时器System.Timers类中的类。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C# MVP]

- mv*@spam.guard.caspershouse.com


DaTurk < mm ****** @ hotmail.comwrote in message

news:11 ********************** @ d57g2000hsg .googlegr oups.com ...
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.



3月30日下午3:43,Nicholas Paldino [.NET / C#MVP]"

< m ... @ spam.guard.caspershouse.comwrote:
On Mar 30, 3:43 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:

DaTurk,


你想要的是System.Timers类中的Timer类。


希望这会有所帮助。


-

- Nicholas Paldino [.NET / C#MVP]

- m ... @ spam.guard.caspershouse.com


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


新闻:11 ********************** @ d57g2000hsg.googlegr oups.com ......
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.


我总是运用system.threading.timer好运。我每次创建一个新的计时器

来解决一些问题(即49天问题和重叠的工作)。


public void DoIt()

{

计时器t = null;

t =新计时器(

委托(对象状态)

{

t.Dispose(); // t被捕获,所以我们不需要在其他地方持有

。 />

//运行你的东西。


DoIt();

},null,1000,-1)) ;

}


看起来像堆栈递归,但不是因为我们启动异步计时器并返回。

我们安排一个新的计时器每次,只有在我们开始工作之后,所以我们不会因为工作重叠而有b
。但是,下一个作业只在

之前的作业结束后开始,所以可能超过1秒。你可以根据需要随意摆动ms。


-

William Stacey [C#MVP]
PCR并发库: www.codeplex.com/pcr

PSH脚本项目 www.codeplex.com/psobject

DaTurk < mm ****** @ hotmail.comwrote in message

news:11 ********************* @ y80g2000hsf。 googlegro ups.com ...

| 3月30日下午3:43,Nicholas Paldino [.NET / C#MVP]"

| < m ... @ spam.guard.caspershouse.comwrote:

| DaTurk,

| >

|你想要的是System.Timers类中的Timer类。

| >

|希望这会有所帮助。

| >

| -

| - Nicholas Paldino [.NET / C#MVP]

| - m ... @ spam.guard.caspershouse.com

| >

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

| >

|新闻:11 ********************** @ d57g2000hsg.googlegr oups.com ...

| >

| >

| >

|

| >

|我正在创建一个需要使用计时器来执行

|的应用程序静态方法每秒调用一次。我的问题是,什么是

|最好的计时器使用?我知道有几个,但我想使用

|计时器可能是最可靠的,并且希望用

|设计高绩效。提前谢谢.-隐藏引用的文字 -

| >

| - 显示引用文字 -

|

| System.Timer会是最好的选择吗?我需要最可靠的,并且

|高性能。

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


这篇关于什么是最好的计时器使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆