Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

if webbrowser hangs, then retry, how to check if hanging c#

Posted on 2012-08-22
8
Medium Priority
?
742 Views
Last Modified: 2012-09-04
Hello All,

I am using a winapp form c# to login and navigate deep into a webpage, upload a file, download a file.  All this works successfully... MOST of the time.  Everyonce in a while, when I hit the download button, the system seems to hang.  Like a webpage that never fully loads.  My goal here is if the page doesn't load, then close all webbrowsers and re-try process.  Anyone have any ideas to see if page is hung on loading.  My first thought was to have some sort of timer to check, if doesn't load,  then start over.

Can anyone suggest something better?
0
Comment
Question by:solarissf
  • 6
  • 2
8 Comments
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 38330643
How are you accessing web pages? Are you controlling external instances of Internet Explore, using the WebBrowser control, or something like the HttpRequest class?

I general, a timer of some sort seems like it'd be a good approach. The details of implementing something like that will depend on your particular application - how your existing code currently works.

You may want to run the web browser/download on a background thread, this way if it fails the thread that your application's user interface is running on won't be affected, and the user won't see the "Not Responding..." messages. Your main UI thread would wait for the background thread to complete, unless a Timeout that you've specified expires in which case you can try to safely stop the thread, or forcibly kill it, notify the user and prompt them if they'd like to try again (if it's a persistent error, like the Internet connection is down, you wouldn't want your application to just continually retry, hence the user prompt).
0
 

Author Comment

by:solarissf
ID: 38338408
Hi there,

Thanks for the assistance.  I am opening a webbrowser object inside my winform in c#.
Here's my idea and please feel free to rip apart with a better concept.

My idea is if I get to the end of my code the timer will stop and break the loop.  If not it will start over.  Then maybe put some counter and if it tries twice, completely stop program so I can investigate.  

I'm assuming someone has a better suggestion... hopefully.

"code"
"code"
x=0
dountil x<>0
  start timer   (timer will run every 2 minutes)
        navigate
        navigate
        navigate
        download
        navigate
   stop timer
   break loop
end loop
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 2000 total points
ID: 38340294
That sounds like a good approach - the only other thing you might want to consider is use of threads - otherwise your application is going to show as "Not Responding" in Windows. I'll put together a simple example as soon as I get to q computer.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:solarissf
ID: 38340472
just to put a bit more background... in the navigating section I am launching 2 new short threads.  they both finish before the end of the main navigation.  I've put them in to handle pop up windows where the main code pauses when they are on screen.
0
 

Author Comment

by:solarissf
ID: 38341088
So I've implemented and I'm a bit stuck on something.  When I test a fake navigation hanging point... such as below..  The code does restart and it completed and works the navigation/downloading section as it should... the problem is when it is done.  Instead of moving on in the code, (outside the timer area) it goes right back to the point where it originally got hung on.  But since I already did it successfully I need it to exit out of the whole timer area.  ANy idea what I'm doing wrong?


x=0
dountil x<>0
  start timer   (timer will run every 2 minutes)
        navigate
        navigate (fake hanging point)
        navigate
        download
        navigate
   stop timer
   break loop
end loop
0
 

Author Comment

by:solarissf
ID: 38341349
so I think I found where the problem lies but I don't know how to fix it.
the timer I am using... I used Invoke(new naviTimer(naviTimerFunction) to launch the section of navigation/download.  So when the fake hang hits... then 2 minutes passes, it resets (like its supposed to).  Then completes properly... soon as the navigation/download completes, I need it to go to the main code, but instead it hits the Invoke like again in the timer... and it goes back to where fake hanging originally paused and tries to continure from there.  ideas??
0
 

Author Comment

by:solarissf
ID: 38342599
tried a different way, used systems.timer.timer and before it even runs the first time it gives me error stating not a single thread.  Cant get that to work either..... ugh
0
 

Author Comment

by:solarissf
ID: 38363750
ended up using a combination of timers and navigation event, thanks
0

Featured Post

Technology Partners: 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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month20 days, 18 hours left to enroll

810 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