|
-
Sep 5th, 2010, 04:14 AM
#1
Thread Starter
Hyperactive Member
use webbrowser in multithread?
I'm working on a project. It is a windows form app which has a webbrowser. The app navigates to a url automatically, checks the url's document, and jumps to another url (depends on the document). It works fine. But, now, the problem is the project needs check many urls, so, I'm trying to make it as a MDI form project. when the start button clicked, it create a control thread, in the thread, it launchs 10 MDI forms (within main form), each form does the work for different urls. once done, then launch the next 10 urls.
It works. However, I noticed that, although 10 MDI forms are open, the navigating part in their webbrowser seems run in sequencial. I thought these 10 MDI forms will load 10 urls at the same time, do the work at the same time, but I found that it seems they do load urls one by one, not at the same time.
so, I did some research, it seems webbrowser can only be run STA mode. does it mean I can not use multithread to load different urls at the same time?
basically, I want to have a multi tab webbrowser, and navigate to different urls in these tabs at the same time. is there a way to do this?
thanks
bear
-
Sep 5th, 2010, 04:51 AM
#2
Re: use webbrowser in multithread?
All the UI is generally managed in one thread. Just because you have multiple forms doesn;t mean that you have multiple threads. If you really want to have each WebBrowser process in a different thread then you won't be able to use MDI. You'd have to start a new thread explicitly, then create the form on that thread. A form owned by a different thread cannot be hosted as an MDI child.
With regards to STA, you must set the ApartmentState property of your Thread before calling Start.
-
Sep 5th, 2010, 12:50 PM
#3
Thread Starter
Hyperactive Member
Re: use webbrowser in multithread?
so, all MDI children are actually in the same thread? I thought they are on different, 
I did a quick test, well, you are correct. if I create a new thread for each form (was mdi form), and then show the form in the thread, the browser in the form of all threads work simultaneously, which is what I want.
the reason I used MDI is because it provides a UI to manage these forms easily.
so, if I use above method, which seems I have to use, is there any suggestion of how to manage these forms? something like cascade window, .... The most important thing is: can I somehow put these forms in a container form, so, if I minimize the container form, I can minimize all of them (same as main form for the MDI). Any way to simulate a MDI UI? otherwise, suddenly, the screen pops 10 forms, looks like virus, 
again, thanks for your help, appreciate it.
bear
-
Sep 5th, 2010, 09:20 PM
#4
Re: use webbrowser in multithread?
You may be able to use the SetParent API to put the forms inside a common parent because you can do that with windows from different processes. The reason that you can't use standard MDI is because you cannot access the Handle of any control on any thread other than the one that created it. Having an MDI child inside an MDI parent requires the parent to access the child's Handle. As a last resort, you can minimise all the forms on different threads easily enough like so:
vb.net Code:
For Each child As Form In childForms Me.MinimiseForm(child) Next
vb.net Code:
Private Sub MinimiseForm(ByVal formToMinimise As Form) If formToMinimise.InvokeRequired Then formToMinimise.Invoke(New MethodInvoker(AddressOf MinimiseForm)) Else formToMinimise.WindowState = FormWindowState.Minimized End If End Sub
-
Sep 7th, 2010, 07:12 PM
#5
Thread Starter
Hyperactive Member
Re: use webbrowser in multithread?
I tried to open forms, then use setparent to set the the main form as their parent. then, I found that, once I did this, the main form becomes responding event very slowly when I opened 4 forms. I guess it is because the forms are in differennt threads which make the parent form slow. anyone know whether this is true?
If I simply open the form directly (with no parent), then even I opened 16 forms, there is no delay (although have another problem, which I will post it in another thread ).
So, for now, I have to open the forms as standard alone form. It is ok for now. But I really want to figure out a way to use MDI frame and make each form has its own thread for the web browser control.
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|