VB.NET - Wait for form to finish loding before continuing with code.

I have a sub that uses a ping command to determine if specific IPs respond and then sets various attributes accordingly.  This process takes 10-15 seconds.

I don't want the user to think the application has hung, so I have a form that displays with a marquee progress bar and a message saying "Please wait...."

I tried calling the sub from the form_load but the form doesn't finish displaying before the sub starts.  In fact the please wait screen looks hung until the sub finishes, then displays properly. (I will insert code to close it anyway once I get it working properly.

How can I instruct the code to wait for the form to finish loading before running the sub?

I tried putting the sub call in .gotfocus, but it reacts the same.

Any help is appreciated.
LVL 1
joeyjacksonAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
...because all of the work you are doing to ping the IPs is preventing the GUI from processing its normal messages (like painting itself).

You need to move the PING work to another thread.

The easiest way to do this is with the BackgroundWorker() control:
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx
0
 
x77Connect With a Mentor Commented:
You can use Aplication.DoEvents, but generally it´s not necessary.

Dim f as new InfoForm
f.show
Application.DoEvents
......
Do the work
.....
f.close
0
 
joeyjacksonAuthor Commented:
Thanks for the quick reply.  That's got the form loading, but for some reason the marquee scroll doesn't start until after the work has completed.   Any thoughts on why that might be?
0
 
joeyjacksonAuthor Commented:
Thanks for the help!  x77 your answer was helpful, but it was idle_Mind that addressed the root of the issue, thanks to both of you.
0
All Courses

From novice to tech pro — start learning today.