Question : Do...Loop alternative

Hi Experts,

The attached code waits for a message box to pop up then clicks it away. The problem is that the do...loop is causing this application to terminate incorrectly. How should I poll without using a do loop?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim WinHandle As IntPtr

        Me.Show()

        Do

            Threading.Thread.Sleep(1000)
            WinHandle = FindWindow(vbNullString, "Message box title")

            Application.DoEvents()

            If WinHandle.ToInt32 > 0 Then
                ClickButton()
            End If

        Loop

    End Sub

Answer : Do...Loop alternative

Use a TIMER control....
Random Solutions  
 
programming4us programming4us