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

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?
solarissfAsked:
Who is Participating?
 
Todd GerbertIT ConsultantCommented:
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
 
Todd GerbertIT ConsultantCommented:
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
 
solarissfAuthor Commented:
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
solarissfAuthor Commented:
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
 
solarissfAuthor Commented:
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
 
solarissfAuthor Commented:
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
 
solarissfAuthor Commented:
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
 
solarissfAuthor Commented:
ended up using a combination of timers and navigation event, thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.