我的问题涉及定时器激活的时钟。通过研究,可以找到最相似的情况:
Two timers with two different intervals C# Form
情况:我有一个用于游戏的应用程序。在这个游戏中,有很多情况下用户必须能够在一秒钟内创建需要精确的时钟和计时器,如果是时钟,则遵循UTC时间。
由于需要跨表单使用变量,因此它们在模块中声明。
Module Global_Variables
' String Variables
' frmMain
Public strMDbPath As String
' Date & Time Variables
'frmMain
Public dtLocalTime As DateTime
Public dtEveTime As DateTime
End Module
Public Class frmMain
Private Sub Page_Load(sender As Object, e As EventArgs)
'Start Eve and Local Time Clocks
tmrMainTimes.Interval = 1000
tmrMainTimes.Start()
End Sub
Private Sub mnuSecuredItemEnableAccess_Click(sender As Object, e As EventArgs) Handles mnuSecuredItemEnableAccess.Click
'Show Enable Access Form (frmFirstAccess)
Dim frmFirstAccess As New frmFirstAccess()
frmFirstAccess.ShowDialog()
End Sub
Private Sub tmrMainTimes_Tick(sender As Object, e As EventArgs) Handles tmrMainTimes.Tick
''Start Local Time
'toolstripItemLocalTime.Text = Format(Now, "HH:mm:ss")
''Start Eve (UTC) Time
'toolstripItemEveTime.Text = Format(Now.ToUniversalTime, "HH:mm:ss")
dtLocalTime = DateTime.Now.ToString("HH:mm:ss")
toolstripItemLocalTime.Text = dtLocalTime
dtEveTime = DateTime.UtcNow.ToString("HH:mm:ss")
toolstripItemEveTime.Text = dtLocalTime
End Sub
Private Sub TimersToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TimersToolStripMenuItem.Click
Dim frmTimers As New frmTimers()
frmTimers.ShowDialog()
End Sub
End Class
这很棒!
问题出在工具部分,我试图让用户启动新的计时器。当我尝试在这个窗体上运行一个单独的时钟时,我启动一个不同的定时器并以相同的方式执行代码,但与其他时钟相比,时钟似乎会丢失一秒钟。
Public Class frmTimers
Private Sub frmTimers_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Start Clock Timer for Timers
TimersClocksStart.Interval = 1000
TimersClocksStart.Start()
End Sub
Private Sub TimersClocksStart_Tick(sender As Object, e As EventArgs) Handles TimersClocksStart.Tick
txtCurrRollEveClock.Text = dtEveTime
End Sub
End Class
我如何1)在多种形式的时钟和定时器之间修复一秒钟的延迟? 2)防止它再次发生?
最多,在应用程序中,需要有五种形式的二十五个时钟/定时器。至少需要大约十种三种形式