Results 1 to 9 of 9

Thread: Opening multiple web pages simultaneously...

  1. #1

    Thread Starter
    Member
    Join Date
    May 2009
    Posts
    42

    Opening multiple web pages simultaneously...

    Hi!
    I'm writing a program which gets the time and date from forums which only show "x hours ago" on the main thread list.
    What I do is get a list of threads, open their print version and fetch the info.
    I'm currently using a single webbrowser, because there's no control array anymore. This makes the proccess very slow.
    Is there a way to open all the threads' print versions simultaneously?
    (BTW, I'm using DOM functions like GetElementsByTag, so I'll need to get the page's "Document" object.)

    Thanks!

  2. #2
    Addicted Member Dark Anima's Avatar
    Join Date
    Sep 2008
    Posts
    183

    Re: Opening multiple web pages simultaneously...

    Can't you get the info with httpWebRequest directly?

    You could create a class, that generates a new thread and a new webbrowser on it, and does what you want. Then just make a lot of those classes, but it won't go very fast either, I once did something very similar.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Opening multiple web pages simultaneously...

    Control arrays are irrelevant. A control array in VB6 was just multiple controls in an array. Why can't you add multiple controls and put them in an array in VB.NET? The fact that the design time support doesn't exist makes no difference. You can still add as many controls as you want and, if you need an array, you can create one in code.

    That said, the very reason that design time support for control arrays doesn't exist in VB.NET is the fact that you can use a single method to handle events for multiple controls. That's all you need to do. Create a single DocumentCompleted event handler or whatever and have it handle the same event for multiple WebBrowser controls.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Member
    Join Date
    May 2009
    Posts
    42

    Re: Opening multiple web pages simultaneously...

    I'll begin by saying I don't have much experience in this kind of programming.

    @Dark Anima
    Can't you get the info with httpWebRequest directly?
    You tell me. Is it possible to get a HtmlDocument object of a page using this method?
    I'd like to know how this can be done.

    @jmcilhinney
    if you need an array, you can create one in code.
    I don't know how to do this. Can you please explain How?
    In practical terms, I'd like to run a loop threw an array of webbrowsers, and each one will open a different forum thread, and later on I'll work on each webbrowser's HtmlDocument.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Opening multiple web pages simultaneously...

    Arrays are a fairly fundamental part of programming. I think that if you don't know how to create an array then you don't really have a grasp of the fundamentals, which you really should have before you start doing things like manipulating web pages in WebBrowser controls. If you learn to walk before trying to run you'd find that you wouldn't fall over so often. Pretty much any beginner tutorial will go through arrays fairly early on. Here are just two examples.

    http://www.startvbdotnet.com/language/default.aspx
    http://www.homeandlearn.co.uk/NET/nets6p1.html
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Member
    Join Date
    May 2009
    Posts
    42

    Re: Opening multiple web pages simultaneously...

    Arrays are a fairly fundamental part of programming. I think that if you don't know how to create an array then you don't really have a grasp of the fundamentals, which you really should have before you start doing things like manipulating web pages in WebBrowser controls. If you learn to walk before trying to run you'd find that you wouldn't fall over so often. Pretty much any beginner tutorial will go through arrays fairly early on. Here are just two examples.
    I don't know how to create an array of webbrowsers.
    If it was as simple as creating an array of integers, I probably wouldn't come to this forum and ask about it, would I.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Opening multiple web pages simultaneously...

    Quote Originally Posted by bugger View Post
    I don't know how to create an array of webbrowsers.
    If it was as simple as creating an array of integers, I probably wouldn't come to this forum and ask about it, would I.
    But it IS as simple as creating an array of Integers. An array is an array. What type its elements are makes no difference to how you create and populate the array.
    vb.net Code:
    1. Dim array1 As Integer() = {1, 2, 3}
    2. Dim array2(2) As Integer
    3.  
    4. array2(0) = 1
    5. array2(1) = 2
    6. array2(2) = 3
    vb.net Code:
    1. Dim array1 As WebBrowser() = {Me.WebBrowser1, Me.WebBrowser2, Me.WebBrowser3}
    2. Dim array2(2) As WebBrowser
    3.  
    4. array2(0) = Me.WebBrowser1
    5. array2(1) = Me.WebBrowser2
    6. array2(2) = Me.WebBrowser3
    As you can see, it's exactly the same.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Member
    Join Date
    May 2009
    Posts
    42

    Re: Opening multiple web pages simultaneously...

    1. Thanks for the example above. I didn't think it was THAT simple.
    2. I was thinking of creating the webbrowser controls during runtime, because I can't really know how many threads there are in a forum. I've seen on others places that in order to do this I'd have to use the "New" command, but I'll have to read more about this, because I didn't quite understand how to use the new control's properties. (Eg. When I try this: msgbox(NewCtl.Document.Body.InnerText) I get an error).

    Anyway, Thanks.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Opening multiple web pages simultaneously...

    If you're creating the controls at run time then an array is a perfect way to store them because if you don't know how many there are then you can't declare discrete variables, e.g.
    vb.net Code:
    1. Private Function CreateWebBrowsers(ByVal count As Integer) As WebBrowser()
    2.     Dim upperBound As Integer = count - 1
    3.     Dim browsers(upperBound) As WebBrowser
    4.  
    5.     For index As Integer = 0 To upperBound
    6.         browsers(index) = New WebBrowser
    7.     Next
    8.  
    9.     Return browsers
    10. End Function
    When you create the array it has the specified number of elements but each element is empty, just like an egg carton with no eggs. You have to create the WebBrowser objects and assign them to the elements of the array.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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