VB.Net计时器问题 [英] VB.Net Timer Issue

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

问题描述

我最近在Windows 2003服务器上使用时发现system.Timers.Timer来自.Net

Framework v1.1不可靠。当

合并到Windows服务中时,timer_elapsed事件将在30到40天后停止执行
。在得知这一点后,我发现在System.Threading.Timer类中记录了相同的

问题,因为

井。这限制了我使用.net框架使用基于计时器的Windows服务

的选项。


我可以将项目转换为.Net Framework 2.0,但是我我不确定

这是否能解决问题。


任何想法都会有所帮助。


谢谢你。

I have recently discovered that the system.Timers.Timer from.Net
Framework v1.1 is not reliable when used on Windows 2003 server. When
incorporated into a Windows Service, the timer_elapsed event will stop
executing after 30 to 40 days. After learning this, I found the same
issue had been documented in the the System.Threading.Timer class as
well. This limits my options for having a timer based windows service
using the .net framework.

I can convert the project to .Net Framework 2.0, but I am unsure
whether or not this will resolve the issue.

Any ideas would be helpful.

Thank you.

推荐答案

为什么我认为实际问题发生在49.7天。这是32位窗口的已知问题(2 ^ 31-1毫秒约为49.7天)。这不是计时器服务停止的,而是内部计时器回到

零并且触发器不再发生了。解决的问题是跟踪它是什么日子或月份(数月或一年中的数字是

足够)以下是一个示例解决方法。 />

模块模块1

Public ReadOnly Interval As New System.TimeSpan(1,0,0)

Public t As New System.Timers .Timer(Interval.Milliseconds)

Public MonthNumber As Integer = Today.Month


Sub Main()

AddHandler t。 Elapsed,AddressOf t_Elapsed

t.Start()

End Sub


Private Sub t_Elapsed(ByVal sender As Object,ByVal e如

System.Timers.ElapsedEventArgs)

如果MonthNumber< Today.Month那么

RemoveHandler t.Elapsed,AddressOf t_Elapsed

MonthNumber = Today.Month

t = New System.Timers.Timer(Interval.Milliseconds)

AddHandler t.Elapsed,AddressOf t_Elapsed

t.Start()

结束如果


''进行计时器事件

End Sub


结束模块

Mike Ober。


" igor" < jo ******** @ yahoo.com写了留言

新闻:11 ********************** @ a3g2000cwd.googlegro ups.com ...
Why do I think the actual problem occurs at 49.7 days. This is a known
issue with 32 bit windows (2^31-1 milliseconds is about 49.7 days). It''s
not that the timer service stops, it''s that the internal timers wrap back to
zero and the trigger doesn''t occur anymore. The work around is to track
what day or month it is (numeric day of month or month of year is
sufficient) Here''s an example workaround.

Module Module1
Public ReadOnly Interval As New System.TimeSpan(1, 0, 0)
Public t As New System.Timers.Timer(Interval.Milliseconds)
Public MonthNumber As Integer = Today.Month

Sub Main()
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start()
End Sub

Private Sub t_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)
If MonthNumber <Today.Month Then
RemoveHandler t.Elapsed, AddressOf t_Elapsed
MonthNumber = Today.Month
t = New System.Timers.Timer(Interval.Milliseconds)
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start()
End If

'' Proceess timer event
End Sub

End Module
Mike Ober.

"igor" <jo********@yahoo.comwrote in message
news:11**********************@a3g2000cwd.googlegro ups.com...

>我最近发现system.Timers.Timer from.Net

在Windows 2003服务器上使用时,框架v1.1不可靠。当

合并到Windows服务中时,timer_elapsed事件将在30到40天后停止执行
。在得知这一点后,我发现在System.Threading.Timer类中记录了相同的

问题,因为

井。这限制了我使用.net框架使用基于计时器的Windows服务

的选项。


我可以将项目转换为.Net Framework 2.0,但是我我不确定

这是否能解决问题。


任何想法都会有所帮助。


谢谢你。
>I have recently discovered that the system.Timers.Timer from.Net
Framework v1.1 is not reliable when used on Windows 2003 server. When
incorporated into a Windows Service, the timer_elapsed event will stop
executing after 30 to 40 days. After learning this, I found the same
issue had been documented in the the System.Threading.Timer class as
well. This limits my options for having a timer based windows service
using the .net framework.

I can convert the project to .Net Framework 2.0, but I am unsure
whether or not this will resolve the issue.

Any ideas would be helpful.

Thank you.



Michael,

感谢您的帮助。我有一些问题。为什么每个月将计时器变量重置为一个新实例的问题确定

问题?如果System.Timers.Timer类经过的事件在内部计时器达到特定的未来时间值时触发,那么任何已经过去的事件都将被触发。 49.7天的点失败了?


据我所知,你提到的内部计时器是服务器重启时启动的计时器,并且会增加直到49.7天

点数。


再次感谢


Michael D. Ober写道:
Michael,
Thank you for your help. I have a couple of questions. Why is it
that resetting the timer variable to a new instance every month fixes
the issue? If the System.Timers.Timer class elapsed events fire when
the internal timer reaches a specific future time value, than wouldn''t
any elapsed event set to fire after the 49.7 day point fail?

As I understand it, the internal timer you mention is the timer which
starts when the server is rebooted and increments until the 49.7 day
point is reached.

Thanks again

Michael D. Ober wrote:

为什么我认为实际问题发生在49.7天。这是32位窗口的已知问题(2 ^ 31-1毫秒约为49.7天)。这不是计时器服务停止的,而是内部计时器回到

零并且触发器不再发生了。解决的问题是跟踪它是什么日子或月份(数月或一年中的数字是

足够)以下是一个示例解决方法。 />

模块模块1

Public ReadOnly Interval As New System.TimeSpan(1,0,0)

Public t As New System.Timers .Timer(Interval.Milliseconds)

Public MonthNumber As Integer = Today.Month


Sub Main()

AddHandler t。 Elapsed,AddressOf t_Elapsed

t.Start()

End Sub


Private Sub t_Elapsed(ByVal sender As Object,ByVal e如

System.Timers.ElapsedEventArgs)

如果MonthNumber< Today.Month那么

RemoveHandler t.Elapsed,AddressOf t_Elapsed

MonthNumber = Today.Month

t = New System.Timers.Timer(Interval.Milliseconds)

AddHandler t.Elapsed,AddressOf t_Elapsed

t.Start()

结束如果


''进行计时器活动

结束子


结束模块


Mike Ober。


" igor" < jo ******** @ yahoo.com写了留言

新闻:11 ********************** @ a3g2000cwd.googlegro ups.com ...
Why do I think the actual problem occurs at 49.7 days. This is a known
issue with 32 bit windows (2^31-1 milliseconds is about 49.7 days). It''s
not that the timer service stops, it''s that the internal timers wrap back to
zero and the trigger doesn''t occur anymore. The work around is to track
what day or month it is (numeric day of month or month of year is
sufficient) Here''s an example workaround.

Module Module1
Public ReadOnly Interval As New System.TimeSpan(1, 0, 0)
Public t As New System.Timers.Timer(Interval.Milliseconds)
Public MonthNumber As Integer = Today.Month

Sub Main()
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start()
End Sub

Private Sub t_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)
If MonthNumber <Today.Month Then
RemoveHandler t.Elapsed, AddressOf t_Elapsed
MonthNumber = Today.Month
t = New System.Timers.Timer(Interval.Milliseconds)
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start()
End If

'' Proceess timer event
End Sub

End Module
Mike Ober.

"igor" <jo********@yahoo.comwrote in message
news:11**********************@a3g2000cwd.googlegro ups.com...

我最近发现system.Timers.Timer from.Net

Framework v1 .1在Windows 2003服务器上使用时不可靠。当

合并到Windows服务中时,timer_elapsed事件将在30到40天后停止执行
。在得知这一点后,我发现在System.Threading.Timer类中记录了相同的

问题,因为

井。这限制了我使用.net框架使用基于计时器的Windows服务

的选项。


我可以将项目转换为.Net Framework 2.0,但是我我不确定

这是否能解决问题。


任何想法都会有所帮助。


谢谢您。
I have recently discovered that the system.Timers.Timer from.Net
Framework v1.1 is not reliable when used on Windows 2003 server. When
incorporated into a Windows Service, the timer_elapsed event will stop
executing after 30 to 40 days. After learning this, I found the same
issue had been documented in the the System.Threading.Timer class as
well. This limits my options for having a timer based windows service
using the .net framework.

I can convert the project to .Net Framework 2.0, but I am unsure
whether or not this will resolve the issue.

Any ideas would be helpful.

Thank you.


我在这里猜测解决方案,因为它听起来像32位毫秒

翻转。至于为什么要创建一个新的计时器 - 这应该初始化

计时器为0。然后它应该可以运行49.7天。当

windows达到49.7天(2 ^ 31-1)毫秒时,它只会翻到0.

Windows 95实际上会变得不稳定(如果它没有从使用中已经完成了
。至于你的问题,我没有答案

因为我使用任务管理器来启动应用程序

在特定时间而不是应用程序代码。


迈克。


" igor" < jo ******** @ yahoo.com写了留言

新闻:11 ********************** @ h40g2000cwb.googlegr oups.com ...
I''m guessing here on the solution as it sounds like the 32 bit millisecond
rollover. As for why the creation of a new timer - this should initialize
the timer to "0" and then it should be able to run for 49.7 days. When
windows hits 49.7 days (2^31-1) milliseconds, it simply rolls over to 0.
Windows 95 would actually become unstable at this point (if it hadn''t
already done so from usage). As for your question, I don''t have an answer
since for longer time periods I use the task manager to start an application
at a specific time and not application code.

Mike.

"igor" <jo********@yahoo.comwrote in message
news:11**********************@h40g2000cwb.googlegr oups.com...

Michael,

感谢您的帮助。我有一些问题。为什么每个月将计时器变量重置为一个新实例的问题确定

问题?如果System.Timers.Timer类经过的事件在内部计时器达到特定的未来时间值时触发,那么任何已经过去的事件都将被触发。 49.7天的点失败了?


据我所知,你提到的内部计时器是服务器重启时启动的计时器,并且会增加直到49.7天

点数。


再次感谢


Michael D. Ober写道:
Michael,
Thank you for your help. I have a couple of questions. Why is it
that resetting the timer variable to a new instance every month fixes
the issue? If the System.Timers.Timer class elapsed events fire when
the internal timer reaches a specific future time value, than wouldn''t
any elapsed event set to fire after the 49.7 day point fail?

As I understand it, the internal timer you mention is the timer which
starts when the server is rebooted and increments until the 49.7 day
point is reached.

Thanks again

Michael D. Ober wrote:

>为什么我认为实际问题发生在49.7天。这是32位窗口的已知问题(2 ^ 31-1毫秒约为49.7天)。它不是计时器服务停止,而是内部计时器回退到零并且触发器不再发生。解决方法是跟踪它是什么日子或月份(数月或一年中的数字是足够的)以下是一个示例解决方法。

模块模块1
Public ReadOnly Interval As New System.TimeSpan(1,0,0)
Public t As New System.Timers.Timer(Interval.Milliseconds)
Public MonthNumber As Integer = Today.Month

Sub Main()
AddHandler t.Elapsed,AddressOf t_Elapsed
t.Start()
End Sub

Private Sub t_Elapsed(ByVal)发件人作为对象,ByVal e As
System.Timers.ElapsedEventArgs)
如果MonthNumber< Today.Month那么
RemoveHandler t.Elapsed,AddressOf t_Elapsed
MonthNumber = Today.Month
t =新的System.Timers.Timer(Interval.Milliseconds)
AddHandler t.Elapsed,AddressOf t_Elapsed
t.Start()
结束如果

''进行计时器活动
结束子

结束模块

Mike Ober。

igor < jo ******** @ yahoo.comwrote in message
新闻:11 ********************** @ a3g2000cwd.googlegr oups.com ...
>Why do I think the actual problem occurs at 49.7 days. This is a known
issue with 32 bit windows (2^31-1 milliseconds is about 49.7 days). It''s
not that the timer service stops, it''s that the internal timers wrap back
to
zero and the trigger doesn''t occur anymore. The work around is to track
what day or month it is (numeric day of month or month of year is
sufficient) Here''s an example workaround.

Module Module1
Public ReadOnly Interval As New System.TimeSpan(1, 0, 0)
Public t As New System.Timers.Timer(Interval.Milliseconds)
Public MonthNumber As Integer = Today.Month

Sub Main()
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start()
End Sub

Private Sub t_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)
If MonthNumber <Today.Month Then
RemoveHandler t.Elapsed, AddressOf t_Elapsed
MonthNumber = Today.Month
t = New System.Timers.Timer(Interval.Milliseconds)
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start()
End If

'' Proceess timer event
End Sub

End Module
Mike Ober.

"igor" <jo********@yahoo.comwrote in message
news:11**********************@a3g2000cwd.googlegr oups.com...

>我最近发现system.Timers.Timer from.Net

Framework v1.1在Windows 2003服务器上使用时不可靠。当

合并到Windows服务中时,timer_elapsed事件将在30到40天后停止执行
。在得知这一点后,我发现在System.Threading.Timer类中记录了相同的

问题,因为

井。这限制了我使用.net框架使用基于计时器的Windows服务

的选项。


我可以将项目转换为.Net Framework 2.0,但是我我不确定

这是否能解决问题。


任何想法都会有所帮助。


谢谢你。
>I have recently discovered that the system.Timers.Timer from.Net
Framework v1.1 is not reliable when used on Windows 2003 server. When
incorporated into a Windows Service, the timer_elapsed event will stop
executing after 30 to 40 days. After learning this, I found the same
issue had been documented in the the System.Threading.Timer class as
well. This limits my options for having a timer based windows service
using the .net framework.

I can convert the project to .Net Framework 2.0, but I am unsure
whether or not this will resolve the issue.

Any ideas would be helpful.

Thank you.



这篇关于VB.Net计时器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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