Can't get timer to work as needed RRS feed

  • Question

  • I need to use a timer to warn the user in a messagebox that the app will exit in 5 seconds.


    I have this at the end of a sub:

    Code Snippet

    If bNewDBLocation Then

    Dim t As Integer


    m_tmrMsgTimer.Interval = 5000 ' Set timer to 5 seconds

    m_tmrMsgTimer.Enabled = True


    MsgBox("Application" & vbCrLf & "will exit in 5 seconds.", MsgBoxStyle.Critical, "Closing Application")

    End If



    This code disables the timer and closes the app:

    Code Snippet

    Private Sub m_tmrMsgTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles m_tmrMsgTimer.Tick


    m_tmrMsgTimer.Enabled = False



    End Sub



    (I've used messagebox styles other than "Critical" that's just what I happened to have in my code when I copied it for this post.)


    If the user clicks OK in the messagebox (whether a button or in the upper right of the messagebox if there is no OK button), the app exits as it should, however, if nothing is done (OK is not clicked) then the app freezes (after the timer runs out).


    How can I warn the user, close that warning, and then shut down the app?



    Tuesday, October 21, 2008 9:39 PM


  • You would need to create a custom dialog which would close itself on timer after whatever time period and use that instead of the message box (which you have no control over).

    Tuesday, October 21, 2008 10:41 PM