1

I have vb.net desktop app that uses mysql. I can connect remotely without any problem. I have timer control that query the database every 10 secs. Now I want to execute multiple Functions without using multiple connections.

Private Sub Timer__Tick()...
    call GET_QUEUED_EMAILS
    call Function2
    Call Function3
End sub

sample function:

Public Function GET_QUEUED_EMAILS(ByVal sql As String)
    Try
             ' Load From DB
            GlobalFunctions.db_connect()
            Dim reader As New MySqlDataReader
            Dim command As MySqlCommand = connection.CreateCommand()
            command.CommandText = sql

            reader = command.ExecuteReader
            If (reader.HasRows) Then
                While (reader.Read())

                       message_id = reader(0).ToString
                       message_status = reader(2).ToString

                    Exit While
                End While
                reader.Close()
                GlobalFunctions.connection.Close()
               call another function here....
            Else
                reader.Close()
                GlobalFunctions.connection.Close()

            End If
        End If
    Catch ex As Exception
           MessageBox.Show("Error" & ex.Message)
        End Try

End Sub'
4

1 回答 1

0

当第一个计时器结束时使用三个计时器启动第二个计时器

Private Sub Timer1__Tick()...
    call GET_QUEUED_EMAILS
    Timer2.Start
    Timer1.Stop
End sub
Private Sub Timer2__Tick()...
    call Function2
    Timer3.Start
    Timer2.Stop
End sub
Private Sub Timer3__Tick()...
    call Function3
    Timer3.Start
End sub
于 2016-03-22T08:05:52.040 回答