如何使用vb.net使用多个计时器

时间:2016-04-01 04:59:38

标签: vb.net

我正在使用vb.net

我在一个表单中使用2个计时器。表单包含许多文本框,标签和gridview。

一个计时器用于刷新gridview,第二个计时器用于打印我使用线程概念的水晶报告,但它给标签和其他控件带来错误。

我的代码是

Private Sub cmdstart_Click(ByVal sender As System.Object, ByVal e As    system.EventArgs) Handles cmdstart.Click

    Dim timer2 As New System.Windows.Forms.Timer
    AddHandler timer2.Tick, AddressOf mytimer2_tick
    timer2.Enabled = True
    timer2.Interval = 100
    timer2.Start()
End Sub

Public Sub mytimer2_tick(ByVal sender As Object,ByVal e As System.EventArgs)
    ' my printing code

    DirectCast(sender, System.Windows.Forms.Timer).Enabled = True
End Sub

Private Sub frmList_Load(ByVal sender As System.Object, ByVal e As     System.EventArgs) Handles MyBase.Load
    dim timer1 As New System.Windows.Forms.Timer
    AddHandler timer1.Tick, AddressOf mytimer1_tick
    timer1.Enabled = True
    timer1.Interval = 10000
End Sub

Public Sub mytimer1_tick(ByVal sender As Object,ByVal e As System.EventArgs)
    RefreshGrid()
    DirectCast(sender, System.Windows.Forms.Timer).Enabled = True
End Sub

请帮帮我

提前致谢

0 个答案:

没有答案