如何在vb.net中创建多个计时器处理程序 [英] How to create multiple timer handler in vb.net

查看:363
本文介绍了如何在vb.net中创建多个计时器处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 我必须用处理程序创建多个定时器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

那么我该如何实现呢?

推荐答案

code>标签属性的Timer将在您的案例中精美地工作。我目前没有我的IDE,但下面的代码段应该给你的想法。

I believe Tag property of Timer would work beautifully in your case. I don't have my IDE currently, but the following snippet should give you the idea.

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

这篇关于如何在vb.net中创建多个计时器处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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