Hi, I am trying to make a program, what it needs to do is wait for 30 seconds with the form fully working, so you can not notice you are being timed, then after 30 seconds you will get an alert like

MsgBox ("Time's up!")

Thanks.

Comments
N/A
Using a timer is the answer to your question...

What you want to do open a form or close a form or just show a message box ...
First add a timer and change its Enabled property to true.
Then adjust time to 30 seconds ( 1000 is equal to 1 second , so set 30000) .
Add this code in timer :

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        MsgBox("Times Up !")
    End Sub

Or if you want to check it only for first time then

Public Class Form1
    Dim timerflag As Integer
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If timerflag = 0 Then
            MsgBox("Times Up !")
            timerflag = 1
        Else
            Timer1.Enabled = False
        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        timerflag = 0
    End Sub
End Class

If you want to close the form after 30 seconds then Use END before else.

Here is another way:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
		Dim act As Action(Of Integer) = AddressOf ShowMessageBoxAfter
		act.BeginInvoke(30, Nothing, Nothing)	'Waits 30 seconds
	End Sub

	Private Sub ShowMessageBoxAfter(ByVal sleep As Integer)
		System.Threading.Thread.Sleep(sleep * 1000)
		MessageBox.Show("Hi")
	End Sub

That calls the thread.sleep on another thread before showing the message box.

This article has been dead for over six months. Start a new discussion instead.