timer.elapsed是否会启动一个新线程? [英] Does a timer.elapsed start a new thread?

查看:102
本文介绍了timer.elapsed是否会启动一个新线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我在Windows窗体应用程序中使用了一个计时器对象。

..elapsed事件中的代码是否在不同的线程中运行?如果间隔设置为10

毫秒并且在.elapsed事件中执行代码的时间需要1

secocond来完成,会发生什么?


1)定时器启动。 10毫秒后代码被执行并且计时器停止。

代码完成后,1秒钟后,计时器继续。 10毫秒

以后执行代码并停止计时器。等等

2)计时器启动。 10毫秒后执行代码。 10毫秒

再次执行代码等等。

3)定时器启动。 10毫秒后,代码被执行并且计时器停止。

1秒后计时器再次启动。但是因为1秒钟更长

然后立即执行代码10毫秒。

4)还有别的吗?


Philip Wagenaar

Hello,

I am using a timer object in my Windows Forms Application. Does the code in
..elapsed event run in a diffrent thread? If the interval is set to 10
milliseconds and the time to execute the code in the .elapsed event takes 1
secocond to complete, what happens?

1) Timer starts. 10 milliseconds later the code is executed and timer stops.
When code is done, 1 seconds later, the timer continues. 10 milliseconds
later the code is executed and the timer stops. etc etc
2) Timer starts. 10 milliseconds later the code is executed. 10 milliseconds
the code is executed again, etc, etc.
3) Timer starts. 10 milliseconds later the code is executed and timer stops.
1 seconds later the timer starts again. But because the 1 second is longer
then the 10 milliseconds the code is executed right away.
4) Something else?

Philip Wagenaar

推荐答案

Philip,


简单回答,对于线程,你需要使用线程。计时器,这不是最令人愉快的课程。

http://msdn.microsoft.com/library/de...classtopic.asp < br $> b $ b(不要问我比这个更多的信息,我尽量避免这个。)


我希望这有帮助,


Cor


" Philip Wagenaar" < pH值************* @ online.nospam> schreef在bericht

新闻:DE ********************************** @ microsof t.com ...
Philip,

Easy answer, for threading you need to use the threading.timer which is not
the most pleasant class to use.

http://msdn.microsoft.com/library/de...classtopic.asp

(Don''t ask me more information than this, I try to avoid this one).

I hope this helps,

Cor

"Philip Wagenaar" <ph*************@online.nospam> schreef in bericht
news:DE**********************************@microsof t.com...
您好,

我在Windows窗体应用程序中使用了一个计时器对象。
.elapsed事件中的代码是否在不同的线程中运行?如果间隔设置为10
毫秒,并且在.elapsed事件中执行代码的时间需要完成,那么会发生什么?

1 )计时器启动。 10毫秒后代码执行,定时器停止。
代码完成后,1秒钟后,定时器继续运行。 10毫秒
稍​​后执行代码并停止计时器。等等
2)定时器启动。 10毫秒后执行代码。 10
毫秒
代码再次执行,等等。
3)定时器启动。 10毫秒后,代码被执行,计时器停止。
1秒后计时器再次启动。但是因为1秒钟更长,然后立即执行10毫秒代码。
4)其他什么?

Philip Wagenaar
Hello,

I am using a timer object in my Windows Forms Application. Does the code
in
.elapsed event run in a diffrent thread? If the interval is set to 10
milliseconds and the time to execute the code in the .elapsed event takes
1
secocond to complete, what happens?

1) Timer starts. 10 milliseconds later the code is executed and timer
stops.
When code is done, 1 seconds later, the timer continues. 10 milliseconds
later the code is executed and the timer stops. etc etc
2) Timer starts. 10 milliseconds later the code is executed. 10
milliseconds
the code is executed again, etc, etc.
3) Timer starts. 10 milliseconds later the code is executed and timer
stops.
1 seconds later the timer starts again. But because the 1 second is longer
then the 10 milliseconds the code is executed right away.
4) Something else?

Philip Wagenaar



" Philip Wagenaar" < pH值************* @ online.nospam> schrieb:
"Philip Wagenaar" <ph*************@online.nospam> schrieb:
我在Windows窗体应用程序中使用了一个计时器对象。
.elapsed事件中的代码是否在不同的线程中运行?
I am using a timer object in my Windows Forms Application. Does the code
in
.elapsed event run in a diffrent thread?




''System.Windows.Forms.Timer''运行于同一个帖子。


-

MS Herfried K. Wagner

MVP< URL:http:// dotnet。 mvps.org/>

VB< URL:http://classicvb.org/petition/>



''System.Windows.Forms.Timer'' runs on the same thread.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


好的,普通计时器如何工作? (1,2,3或其他东西(见我的

原帖))


" Cor Ligthert [MVP]"写道:
Ok, and how does the normal timer work? (1,2,3 or something else (see my
original post))

"Cor Ligthert [MVP]" wrote:
Philip,

简单的回答,对于线程你需要使用threading.timer,这不是最令人愉快的类使用。

http://msdn.microsoft.com/library/de...classtopic.asp

(不要问我比这个更多的信息,我尽量避免这个。)

我希望这有帮助,

Philip Wagenaar < pH值************* @ online.nospam> schreef在bericht
新闻:DE ********************************** @ microsof t.com。 ..
Philip,

Easy answer, for threading you need to use the threading.timer which is not
the most pleasant class to use.

http://msdn.microsoft.com/library/de...classtopic.asp

(Don''t ask me more information than this, I try to avoid this one).

I hope this helps,

Cor

"Philip Wagenaar" <ph*************@online.nospam> schreef in bericht
news:DE**********************************@microsof t.com...
您好,

我在Windows窗体应用程序中使用了一个计时器对象。
.elapsed事件中的代码是否在不同的线程中运行?如果间隔设置为10
毫秒,并且在.elapsed事件中执行代码的时间需要完成,那么会发生什么?

1 )计时器启动。 10毫秒后代码执行,定时器停止。
代码完成后,1秒钟后,定时器继续运行。 10毫秒
稍​​后执行代码并停止计时器。等等
2)定时器启动。 10毫秒后执行代码。 10
毫秒
代码再次执行,等等。
3)定时器启动。 10毫秒后,代码被执行,计时器停止。
1秒后计时器再次启动。但是因为1秒钟更长,然后立即执行10毫秒代码。
4)其他什么?

Philip Wagenaar
Hello,

I am using a timer object in my Windows Forms Application. Does the code
in
.elapsed event run in a diffrent thread? If the interval is set to 10
milliseconds and the time to execute the code in the .elapsed event takes
1
secocond to complete, what happens?

1) Timer starts. 10 milliseconds later the code is executed and timer
stops.
When code is done, 1 seconds later, the timer continues. 10 milliseconds
later the code is executed and the timer stops. etc etc
2) Timer starts. 10 milliseconds later the code is executed. 10
milliseconds
the code is executed again, etc, etc.
3) Timer starts. 10 milliseconds later the code is executed and timer
stops.
1 seconds later the timer starts again. But because the 1 second is longer
then the 10 milliseconds the code is executed right away.
4) Something else?

Philip Wagenaar




这篇关于timer.elapsed是否会启动一个新线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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