Click here to Skip to main content
15,906,558 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I am using WebBrowser and want it to refresh every time it loads the same page, it will be doing this about every 10 sec. so I need fast code, I have seen the code on msdn it is to long.

Below is the code I have now, but I have tried every thing I can think of and still can not get it to refresh

Sub ShowIEScr(mywebpage as string)
  dim wb as new WebBrowser 
  wb = WebBrowser1 'Tried this to see if I could kill and reload did not work
  
  wb.Refresh(WebBrowserRefreshOption.Completly) 'all option do not work

  wb.Navigate(mywebpage) 'this is the hart of what I want to do the rest of the code is just tring to get it to refresh
  wb.visible = true 'set to false elswhere, did not work
  wb.WebBrowserShortcutsEnabled = true
  SendKeys.send("{F5}")  'still did not work
  'I set the hight and width then 
end sub


I have tried to use the AxWebBrowser with same code tries no luck

Every thing I try I can not get the Browser to refresh
I loaded same webpage in IE and it will refresh when F5 is hit
The above sub is called from a timmer
Also mywebpage changes every call to a different page then rotates back to original
Not sure if it matters but this app needs to run as a Windows service have not tried to run as a exe but do not think it matters.
Posted
Updated 7-Jun-11 14:23pm
v3
Comments
Tarakeshwar Reddy 7-Jun-11 20:24pm    
Updated tags

What you do makes no sense at all. You create a new Browser every time your function is called. You don't add this instance of the Browser to any control. Essentially, you don't do anything. You just create new instances and never show what you do.

Instead, you need to have only one instance of the Browser. Make it a member of your form class. You should added this instance as a child control to a form or a panel. It looks like you already did it, but don't use this instance of the Browser — no wonder it does not refresh.

(I feel you need to learn very basics of classes, instances, OOP, events, etc. This component is pretty tricky to use. With your understanding of things I can foresee more and more trouble. Try to learn all that on some really simple examples.)

And do yourself a favor — forget SendKeys.

—SA
 
Share this answer
 
Comments
mustybob 8-Jun-11 8:56am    
I am sorry I did not word the question very well of course I started with vaild real code not the code I had above, what I was tring to do with the post was to show what I have tried, and some things made more sense then others. I posted this looking for someone who does not think this component is pretty tricky and has a good understanding of the Browser. I do agree with SendKeys and hated to admit to tring it, but I wanted to show that I was desperate and willing to try anything
Sergey Alexandrovich Kryukov 8-Jun-11 18:30pm    
This is not a problem at all. Your issue report is not bad, actually, as I was able to see the problem pretty soon. Please, try to fix this problem by making sure you work with the same instance of the Browser, the one added to your UI.

If if does not work, please ask a follow-up question and notify me by replying this comment. I used to work intensively with this component and will have a good change to help.

If it does work, please formally accept this answer (green button) -- thank you.

--SA
mustybob 9-Jun-11 9:58am    
This turned out to be an interesting problem and I will get into that in a minute.
But when I posted the above I did it so to show what I have tried beyond what would and should be the normal way of using this component my original post did not look like real code and I did that on purpose just to show what I have tried someone edited my post to make the listing I had look like real code. So the first couple lines I was showing that I tried to create an instance the destroy it every time in hopes of forcing it to refresh now I did not bother to show the reaming code because I assumed that the reader would understand that. The next thing I tried to show was that I used and tried refresh in just about every combination that there was. Then of course I put in the only line that has to be there Navigate just to make sure that no one would think that is the fix.
I did try different visible options before and after true/false etc.
Then tried to play with short cuts (some ideas are better then others)
I tired other things that I don’t even want to admit I did they were pretty off the wall. But I hoped to show how desperate I was by using Send Keys (is it not amazing how much so called professional coders use this crutch)
So any way thanks for you offer to help and you are absolutely right they way the code is shown on the post your solution is the correct one, however is was not the final solution to my issue and that is what I find very interesting and maybe you will also.
If I set the Application type to Windows service the browser will not refresh but if I change to Windows Application all works just fine, I am not changing code at all just the target Application type, this I don’t really understand but don’t have time to look into it right now, the customer wants VB or I would rewrite it in C and see if it did the same thing. You also got to wonder if it is VS or XP pro or if I just do not understand windows services well enough and this can’t be done or a setting needs to be changed. Meanwhile I wanted the app to be a service as it needs to run as a screen saver under all user accounts on many different machines but I can get around that (I think). Now that I have it working my next step is to get it working on a Thin client running Linux (that should be fun)
If you have any ideas they will be greatly welcome, I can’t post the complete code as this customer has purchased it but from the above you should be able to get the general idea of what I am doing, and now I am not sure that even continuing in this forum is appropriate as it does not look to be a VB coding thing. So I will accept your solution, I am going wait a little while (not sure if I do are dialog will be prevented or not)
Webbrowser needs to be navigated first.

Then Refresh works.

Webbrowser.Navigate("url")


when loads,

then refresh it through timer or button.

Webbrowser.Refresh()

OR,
Webbrowser.Refresh(Completely)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900