if webbrowser multiple navigation hangs, then retry, how to check if hanging c#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: if webbrowser multiple navigation hangs, then retry, how to check if hanging c#

  1. #1
    Join Date
    May 2011
    Posts
    2

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

    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??
    Code:
    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

  2. #2
    Join Date
    Apr 2010
    Posts
    131

    Re: if webbrowser multiple navigation hangs, then retry, how to check if hanging c#

    Without looking at your code, I hear code execution was returning to the "wrong" place. If you don't want code to run where execution returns after the timer resets, just use a boolean like "bool alreadyRun" or soemthing, set it to false normally, and true when the timer hits. Warp the remainder of the code from the return spot in an IF/THEN using the bool as the test, such that when execution returns to the point it left off, it will no longer run the code:

    Code:
    bool alreadyRun = false;
    void onceThisRunsCodeWillNoLongerBeExecuted(){
        //if timer trips, call this method
        alreadyRun = true;
    }
    void executeNavigation(string url){
        if(!alreadyRun){
            WebBrowser1.Navigate(url);
        }
    }
    void mainExecutionMethod(){
      executeNavigation(url1);
      executeNavigation(url2);
      executeNavigation(url3);
    }
    Instead of using a bool & testing for true/false, you could use an int and test for value if you need to see how many times the timer tripped.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center