troubleshooting Question

Do...Loop alternative

Avatar of DColin
DColinFlag for Thailand asked on
Visual Basic.NET
5 Comments1 Solution237 ViewsLast Modified:
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?
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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros