VB.Net计时器勾选

时间:2017-07-23 13:31:18

标签: vb.net timer

我有几个有定时器的用户控件(我已经删除了除了一个之外的所有用户控件以查看是否存在问题),它们已启用并设置为1000毫秒间隔。我遇到的问题是我在计时器中调用的每个子组在开始计数之前连续触发5次。我甚至删除了If语句,将Timer间隔设置为60000并且只调用一个Sub。问题仍然存在。

任何帮助将不胜感激!

间隔设置为1000

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Static j As Integer
    Static i As Integer

    '1 min Timer
    If i >= 60 Then
        popupmsg()
        i = 0
    Else
        i = i + 1
    End If

    '15 Sec Timer
    If j >= 15 Then
        UpdateGrid()
        j = 0
    Else
        j = j + 1
    End If
End Sub

间隔设置为60000

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    popupmsg()
End Sub

使用Sub Called

进行更新
Public Sub popupmsg()
    Dim dt As DataTable = Tbl_Mod_HaulerLoadsTableAdapter1.GetDataBy_spGetLastInsertedRowFromTbl_Mod_HaulerLoadsbyAssetID(iAssetID)
    If dt.Rows.Count = 0 Then
    Else
        HaulerLoadID = dt.Rows(0).Item("HaulerLoadsID")
        If iHaulsCount = 0 Then
            iHaulsCount = HaulerLoadID
        Else
            If iHaulsCount < HaulerLoadID Then
                If dt.Rows(0).Item("HaulerLoadsDispatched").ToString = "" Then
                    If dt.Rows(0).Item("HaulerLoadsLogOperator").ToString <> UserID Then
                        If frmMainNew.AcceptHaulAlert = True Then
                            iHaulsCount = HaulerLoadID
                            frmMainNew.AlertControl1.Images = frmMainNew.ImageList2.Images(1)
                            frmMainNew.AlertControl1.Show(frmMainNew, "Hauler", "There is a New Hauler Load Item", frmMainNew.ImageList2.Images(1))
                        End If
                    Else
                    End If
                End If
            Else
            End If
            iHaulsCount = HaulerLoadID
        End If
    End If
    dt.Dispose()
End Sub

1 个答案:

答案 0 :(得分:0)

你不必使用静电,但昏暗。 Static指定一个或多个声明的局部变量将继续存在,并在声明它们的过程终止后保留其最新值。 i和j仅初始化为0一次。