Results 1 to 6 of 6

Thread: Prevent program freeze

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    21

    Prevent program freeze

    Whenever I open my custom browser
    my program freezes untill the loading has finished.

    Is this normal?
    And if it is then how can I prevent my program from not allowing me to go back to the other form untill the loading has completed?

    I'm using this url as a start up page for my custom browser;
    http://www.runescape.com/game.ws

    it links directly to a java-based game.
    when the game loads it checks for updates etc ( java app )

    so can I prevent my program from freezing or not ?
    It looks as if my custom browser form keeps demanding focus ..
    Not that I'm able to change it by clicking..
    I can at most make my program create the msg:
    Not responding..
    if I click on the browser form while loading.
    If I wait it loads in about 10-15 seconds.

  2. #2
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: Prevent program freeze

    Look up multithreading. You need to throw the code that loads your stuff into it's own thread so it doesn't freeze your UI while it runs.
    Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".


    VS 2008 .NetFW 2.0

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    21

    Re: Prevent program freeze

    Okay will do thanks

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    21

    Re: Prevent program freeze

    .. Code:
    1. Public Class Browser
    2.     Public thread As System.Threading.Thread
    3.  
    4.     Private Sub Browser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.         Dim thread As New System.Threading.Thread(AddressOf DoCode)
    6.         Do While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
    7.             thread.Start()
    8.         Loop
    9.     End Sub
    10.  
    11.     Public Sub DoCode()
    12.         WebBrowser1.Navigate("http://www.runescape.com/game.ws")
    13.     End Sub
    14.  
    15. End Class

    Now I looked up threading etc..
    I tried the backgroundworker and threading and neither of them solved my problem..
    So either I'm doing this wrong or it's something else x(

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    21

    Re: Prevent program freeze

    Code:
        Dim MyThread As System.Threading.Thread
        Dim frmTest As New Form
        Dim Browser As New WebBrowser
    
        Public Sub DoLaunch()
            frmTest.Height = 778
            frmTest.Width = 712
            frmTest.Controls.Add(Browser)
            Browser.Dock = DockStyle.Fill
            Browser.ScrollBarsEnabled = False
            Browser.Navigate("http://www.runescape.com/game.ws")
            frmTest.Show()
        End Sub
    
        Private Sub btnPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlay.Click
            MyThread = New System.Threading.Thread(AddressOf DoLaunch)
            MyThread.Start()
        End Sub
    I figured that to launch my thread correctly I'd have to put all the code in 1 thread. So instead of using a premade form I started off fresh.
    But now I get the following error and I can't make sense of the online solutions .. :s

    error:Unable to get the window handle for the 'WebBrowser' control. Windowless ActiveX controls are not supported.

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Prevent program freeze

    You don't need multi-threading, nor would it work in this situation.
    All you need is to use the events correctly.

    This is what you should do:
    1. Navigate to the page of your interest.
    2. Use the WebBrowser DocumentCompleted event to determine when the webpage has loaded fully and take whatever action you want to based on that.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

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



Click Here to Expand Forum to Full Width