none
Webbrowser not navigating to desired URL.

    Question

  • I'm automating a download,and I know the URL to the download page. Well, not exactly. This URL is indeed what I need to use, but the website redirects it to the REAL download page. Unfortunately the redirect only happens if I do an exit sub.  That is to say, if I do a loop sleeping one second per iteration, the loop goes on forever waiting for the redirect. But if I  branch out of the loop by inserting an Exit Sub in break mode, I can see the redirect occur onscreen. (I can watch the current page in the web browser transition to the desired download page).

    The trouble of course is that I don't WANT to do an Exit Sub at that point, so what's the solution? Do I need to call Browser.Navigate on a background thread?


    • Edited by jal2 Thursday, May 10, 2012 7:43 PM
    Thursday, May 10, 2012 7:41 PM

Answers

  • Post a call (BeginInvoke) to whatever processing has to be continue and exit the sub.  Common pattern.  Use the same pattern you would use if you want to continue code execution when executing a ShowDialog statement.
    • Marked as answer by jal2 Thursday, May 10, 2012 8:38 PM
    Thursday, May 10, 2012 8:05 PM

All replies

  • And by the way I have to use the redirect, as far as I can tell, since the URL seems to consist in part of esoteric info. I don't think there's a way to know the "final destination" in advance.

    Thursday, May 10, 2012 7:43 PM
  • Post a call (BeginInvoke) to whatever processing has to be continue and exit the sub.  Common pattern.  Use the same pattern you would use if you want to continue code execution when executing a ShowDialog statement.
    • Marked as answer by jal2 Thursday, May 10, 2012 8:38 PM
    Thursday, May 10, 2012 8:05 PM
  • Post a call (BeginInvoke) to whatever processing has to be continue and exit the sub.  Common pattern.  Use the same pattern you would use if you want to continue code execution when executing a ShowDialog statement.

    I actually realized my mistake later - I should have been calling Application.DoEvents in the sleep loop.
    Thursday, May 10, 2012 8:39 PM
  • Two things to never do on the UI thread.  Application.DoEvents and Sleep.  Sleep is OK on background threads, but DoEvents never.
    Thursday, May 10, 2012 9:00 PM