?
Solved

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

Posted on 2010-01-11
4
Medium Priority
?
2,449 Views
Last Modified: 2012-05-08
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.
0
Comment
Question by:joeyjackson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Assisted Solution

by:x77
x77 earned 200 total points
ID: 26285958
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
 
LVL 1

Author Comment

by:joeyjackson
ID: 26286089
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 800 total points
ID: 26286297
...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
 
LVL 1

Author Closing Comment

by:joeyjackson
ID: 31676403
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

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

777 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