Hello All,

I am using a winapp form c# (.net4.0)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 ALL the pages don't load successfully, 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.

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.

Concept is timer launches Invoke(naviFunction). If it gets to the end of naviFunction then just break loop and continue. However, if the webbrowsing hangs somewhere, then the 2 minute timer will get hit, and restart the whole process.

Then maybe put some counter and if it tries twice, completely stop program so I can investigate.

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.

So I've implemented and I'm a bit stuck on something.
When I put a normal process everything works successfully.
When I test a fake navigation hanging point... such as below.. The code does restart at 2 minutes and it completes the re-cycle successfully. 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?

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(naviTimer) again in the timer... and it goes back to where fake hanging originally paused and tries to continure from there. ideas??

maincode
{
x=0
dountil x<>0
   start timer   (timer launched instantly)
    if naviTimerFunction completed, then break loop
   stop timer  
loop 

...continue code
...continue code
...continue code
...continue code

}

timer()
{
    reset timer interval to 2 minutes
    Invoke(new naviTimer(naviTimerFunction))

}

naviTimerFunction
{
        navigate
        navigate (fake hanging point!!!)
        navigate  (start sub thread)
        download  (end sub thread)
        navigate  (start sub thread)
    navigate (end sub thread)
    stoptimer
}

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. Cannot create webbrowser objects. Cant get that to work either..... ugh

Sounds like a cross threading issue, look into timercallbacks, and asynchronous processing. Without the actual code its hard to debug a theoretical model...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.