WebBrowser control, questions about NavigateError event
Posted on 2004-04-07
I've got a web page that is actually a time and attendance timeclock. This web page refreshes once a minute to provide an updated time on the page, equal to the host's time. Occasionally the host is not available and the page ends in a HTTP 500 (Internal Server Error) code.
Some of my end users are not sofisticated and don't really understand why the HTTP 500 screen appears instead of the clock display. To them, it's simply "down". If I do a refresh (F5), 99.9% of the time, the clock refreshes and I'm back in business. I can't expect the end users to do this because they don't know that trick and it's far too many people to try to train. The clock should just work, period.
So my solution was to write a VB program that displayed my clock within the WebBrowser control. It has some neat events such as BeforeNavigate, NavigateComplete, and NavigateError. I thought I was home free when I saw that I could get a NavigateError event raised. In that event, I would simply fire off another refresh.
Now here's the problem:
This is difficult to explain but if I start off with a good call, I get my screen, everything is wonderful. If I then shut down my HTTP server, I get the HTTP 500 screen. Also good. My app sees the navigation error and starts a timer which fires off a refresh (basically a new Navigate method). This process continues until I restatr my server. At that time my screen displays with thee updated time and everything is fine. Now to test this thing thoroughly, I stop my HTTP server again. This time however, I still get the NavigateError event, which then causes a new Navigate by design, but instead of getting the HTTP 500 screen, I get a previous, what appears to be a cached version of, my clock screen. I can tell this because the time displayed will be the time of the first HTTP shutdown and not the second. In fact now, if I continue to start and stop my HTTP server, I'll always get the last time I stopped the server. I never get the HTTP 500 screen anymore.
One approach I've tried was to set a flag, bNavErr in the BeforeNavigate event to False. Then if NavigateError fires, I set the flag to True. On my NavigateComplete event, I check this flag and if it's True, I can assume I had a navigation error, so I turn on my timer and start refreshing. In this case I flip-flop between a cached screen and an HTTP error screen for each time the Navigate method is called.
I don't see a means of clearing the cache but I'm wonder if that could be done. Another approach may be to close, then reopen a WebBrowser object but I'm trying to avoid that for performance reasons.