【问题标题】:How to create multiple timer handler in vb.net如何在 vb.net 中创建多个计时器处理程序
【发布时间】:2014-02-09 08:49:56
【问题描述】:
  • 我必须使用处理程序创建多个计时器“n”次。
  • 这将存储在我的 DataGrid 中的一行。
  • 每一行都有一个单独工作的计时器。

我的想法是这样的:

Private Sub CreateTimer()
    Dim tmr As New Timer
    tmr.Interval = 1000 '1 Second
    tmr.Enabled = True
    AddHandler tmr.Tick, AddressOf GlobalTimerTick
End Sub

'A timer tick handler that would work for each timer I add with the sub above
'All timers I created should work seperately
Private Sub GlobalTimerTick(TheTimer as Timer, ByVal sender As Object, ByVal e As EventArgs)
    mynumber = mynumber + 1
    With DataGridView1
        .Rows(n).Cells(4).Value = mynumber " saniye"
    End With
End Sub

那么我该如何实现呢?

【问题讨论】:

标签: vb.net datagridview timer handler


【解决方案1】:

我相信 Timer 的 Tag 属性在您的情况下会很好地工作。我目前没有我的 IDE,但下面的 sn-p 应该会给你这个想法。

Private Sub CreateTimer()
    Dim tmr As New Timer
    tmr.Interval = 1000 '1 Second
    tmr.Enabled = True
    tmr.Tag = ROW_INDEX
    AddHandler tmr.Tick, AddressOf GlobalTimerTick
End Sub

'A timer tick handler that would work for each timer I add with the sub above
'All timers I created should work seperately
Private Sub GlobalTimerTick(ByVal sender As Object, ByVal e As EventArgs)
    mynumber = sender.Tag
    With DataGridView1
        .Rows(n).Cells(4).Value = mynumber " saniye"
    End With
End Sub

【讨论】:

  • 似乎添加 sender.Stop() 也可以,谢谢!
猜你喜欢
  • 2020-03-15
  • 1970-01-01
  • 2011-11-09
  • 2012-11-06
  • 2014-02-26
  • 2011-03-06
  • 1970-01-01
  • 2021-12-21
  • 1970-01-01
相关资源
最近更新 更多