Avatar of PiedBird
PiedBird
 asked on

view hourglass with UseWaitCursor

Hi
using code: Me.UseWaitCursor = true
I can set the mouse pointer on my form to an hourglass. I run this code on a CheckedChanged event of a checkbox. The problem is the hourglass doesn't appear on my screen until all the code in this procedure is finished (the code goes on to try opening a serial port). How do I ensure the hourglass is viewed on my form before the remaining code in the procedure runs?
Thanks
Visual Basic.NET

Avatar of undefined
Last Comment
Fernando Soto

8/22/2022 - Mon
Fernando Soto

Hi PiedBird;

After the statement to set the pointer to an hourglass the next statement try putting the following.

    Application.DoEvents()

Fernando
PiedBird

ASKER
Hello Fernando

Ok
No result.

Here is the code
        Me.UseWaitCursor = True
        Application.DoEvents()
        OpenOrCloseSP2()
        MsgBox("done")
        'Me.UseWaitCursor = False

I put the message box in to see when the pointer changed: ie before or after the messagebox. It changed afterwards!
Fernando Soto

Hi PiedBird;

I think that there might be a bug. If you leave the Application.DoEvents in and run the program and then move the Window while the procedure is running the cursor will change.

Fernando
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
PiedBird

ASKER
   Hi Fernando,
I put this procedure on a new form in a new application.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Application.UseWaitCursor = True
        Label1.Text = "processing"
        Application.DoEvents()
        Dim int As Double = 999999999
        Do Until int = 0
            int -= 1
        Loop
        Label1.Text = "done"
        Application.UseWaitCursor = False

    End Sub

I had trouble moving the window while the procedure was running but after a few seconds it moved and your prediction was correct. However the label text changed when it should (but not without "application.DoEvents()" thankyou).

Have you any more suggestions?

PiedBird
       
SOLUTION
iboutchkine

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
PiedBird

ASKER
Thankyou both.

I maybe should be more forceful in communicating with my machine. Instead of me unobtrusively changing a cursor property and expecting the machine to immediately notice, I should take an approach like, "Oy! Change your cursor!"

Happy regards,
Pied Bird
Fernando Soto

I have the same problem some times, LOL. Glad I was able to help with iboutchkine. ;=)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.