[SOLVED] Interation Not Working - Printable Version +- BP Forums (https://bpforums.info) +-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55) +--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56) +---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8) +---- Thread: [SOLVED] Interation Not Working (/showthread.php?tid=449) |
[SOLVED] Interation Not Working - kismetgerald - 01-18-2012 I'm using a DO interation to loop a function I'm using to test for internet connectivity. The code is working fine, except that when one of the tests is satisfied the loop stops. I want this to continue in the background while the program is running. How can I get this to work? Here's the code: Code: Private Sub checkInternet() Re: Interation Not Working - brandonio21 - 01-18-2012 Well, you can use the BackGround Worker Control to loop through this code without having any effect on the appearance of the application at all. (See more information about a background worker here: <!-- m --><a class="postlink" href="http://www.youtube.com/watch?v=jv4FdoaUMQE&feature=plcp&context=C322e31eUDOEgsToPDskK9c_-OCENEeHwzWSO_Mojs">http://www.youtube.com/watch?v=jv4FdoaU ... wzWSO_Mojs</a><!-- m -->) And since you want the loop to constantly be running, create a timer with the interval of 1000 or something like that, and have the timer tick event call the DoWork() Function of the BackgroundWorker Re: Interation Not Working - xolara - 01-19-2012 You can allso check out my video about Enum and Loops <!-- m --><a class="postlink" href="http://www.youtube.com/watch?v=S3BH9CQAIN0">http://www.youtube.com/watch?v=S3BH9CQAIN0</a><!-- m --> Re: Interation Not Working - kismetgerald - 01-19-2012 Guys, Thanks for your help thus far. So I added a Timer control to the form and in its _Click event, I called the thread I'd already setup to handle the connection check. All is working fine, except that now I'm getting the following exception: Quote:System.InvalidOperationException was unhandled I guess the loop is working but now since the greenbar.png image file had already been displayed in the previous interation, it's saying the file is already open. So question is, how do I release the file before going into another interation? PS. Brandon, I haven't watched your video yet. I'm leaving work now, and will do that when I get home. But I suspect I will run into the same problem. Re: Interation Not Working - brandonio21 - 01-19-2012 To release a file, you may need to do the following: Code: PictureBox4.Image = Nothing Re: Interation Not Working - kismetgerald - 01-19-2012 Brandon, I've already tried that, doesn't work. I get another exception telling me that I cannot call close() on a button while dispose() has been called. This happens because I use a button_click event to close my application, and this exception is thrown if I use the ImageName.dispose() method. I'm starting to loose my hair.........joke....... Re: Interation Not Working - brandonio21 - 01-19-2012 Don't worry! We'll figure this out! If you could attach your whole source file to this thread, we can figure it out even faster! Re: Interation Not Working - kismetgerald - 01-19-2012 Brandon, I got some help from Stackoverflow.com () on how to use the BackgroundWorker and it all works fine. Here's the code I'm using: Code: Private connected As Boolean Re: Interation Not Working - brandonio21 - 01-19-2012 Great! I am glad you got it working! For reference, could you link us to the Stack Overflow page that you used? (Sorry that we were unable to provide sufficient help) Re: Interation Not Working - kismetgerald - 01-20-2012 Brandon, Don't sweat it man. You do a tremendous work here, and I'm learning a lot from your videos. Here's the link to the Stackoverflow.com question/solution concerning this issue: http://stackoverflow.com/questions/8917475/iteration-not-working-as-intended/8917768#8917768 |