?
Solved

VB.NET Order of Events

Posted on 2011-10-06
1
Medium Priority
?
238 Views
Last Modified: 2012-05-12
I have some code in a button click event that run some SQL and returns data. When the button is clicked, I want the label text to say "Please Wait ... running query." The problem is that my label text does not change, it just jumps right into running the query - it is as if it skips changing the label. If I remove the code that comes after the label text change, then it works properly. How do I get it to change the label text first - then run the additional code?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Label6.Text = "Please Wait ... running query"

        Try
            [My Additional Code is here]
        Catch Ex As Exception
            Label6.Text = Ex.ToString
        End Try

End Sub

Open in new window

0
Comment
Question by:NursingCorp
1 Comment
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 2000 total points
ID: 36927926
You're running into a threading problem. When your code runs the UI thread it blocked, so even though you're setting the label the UI thread isn't able to update the UI to actually display the change.

The simplest solution is to allow the message pump to process messages on the queue by calling Application.DoEvents() immediately after you set the label.

The correct way to solve the problem would be to run the [My Additional Code Here] in a separate thread, but that's a more complex solution.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question