gzcjun

I'm trying to simulating a button containing in a form.By reading some reference articles,I'd seen that most of them suggested to use webbrowser control,and then acquire htmldocument2 dispatch to get IHTMLInputButtonElement interface.But I'm now doing real time system,it demanded to get infos as soon as possibly,so I must use multiple threads to solve it.From some articles,I heard that webbrowser control cannot be used in multiple threads environment.So what's the better way

Re: Windows Forms General How can simulate button clicking in multiple threads environment£¿

Thomas Danecker

You can't access any userinterface-item from an other thread than the one which created it. Every time you want to access it, you should call control.Invoke(...) or control.BeginInvoke(...) to run code in it's thread (by doing a SendMessage/PostMessage internally).

You could also use a BackgroundWorker. It's quite nice to use for such tasks.






Re: Windows Forms General How can simulate button clicking in multiple threads environment£¿

gzcjun

Thank you.I still wonder that if there are totally three threads invoke the webbrowser,they do the following:1,send the website string that must be navigated to.2,the webbrowser return the document object when documentcomplete events happened. So, I'm worried about two points:1,how does the webbrowser recognize who send it the dispatch if it satisfy the first thread,and what about the other simultaneously threads 2,I think the efficiency is low,because there is only one webbrowser can handle the request at the same time. Please help me.



Re: Windows Forms General How can simulate button clicking in multiple threads environment£¿

Thomas Danecker

It don't understand the question. Can you clarify it




Re: Windows Forms General How can simulate button clicking in multiple threads environment£¿

gzcjun

OK,I was now doing a real-time Downloading,it's not like the timing ones,when client send the request,for example,to see all the informations of one city,then the central console will start some threads to download the data from multiple websites.So I think it's a time sensitive process.While webbrowser is a STA,so I think it's not fit for the need. You must wonder that why I insist to use a tool like webbrowser,there existing at least another tool,HttpWebRequest can fulfil my request.The reason is:now more and more website begin to add scripts to the button belonging to the form,I cannot exactly know what they do in the script,so I think the most simple way is to simulate the button click,but the HttpWebRequest tool doesn't support it. 1-Use WebBrowser,it doesn't support multiple threads model,cann't satisfy the time sensitive action. 2-Use HttpWebRequest,it cannot support simulating button click. What should I do pls help me.



Re: Windows Forms General How can simulate button clicking in multiple threads environment£¿

Ðãv? S. Â???????

Well, you sure as heck have me confused. You started off talking about simulating a button click, which I'm not sure how that has anything to do with a WebBrowser control, and now you're talking about downloading data Could you please be specific to the issue at hand Are you trying to simulate a button click that resides in a webpage loaded in the WebBrowser control





Re: Windows Forms General How can simulate button clicking in multiple threads environment£¿

gzcjun

I'm sorry to make you confused.Now,I was facing two problem:1)At first,I think webbrowser is a good way to resolve complex problem,it's mainly because some buttons contained in the form always have "onclick" or "onmousedown" events handling script,by simulating the button click,I can avoid analyzing the script.From this point,webbrowser seems to be a good choice.2)The real-time data downloading,as I'd mentioned,I must handle the real-time data download demanding,it seems that multithread is necessary.But I heard that webbrowser doesn't support multithread model,so I was very confused,I don't know how to do next.Hope your help.




Re: Windows Forms General How can simulate button clicking in multiple threads environment£¿

Ðãv? S. Â???????

A few questions:
1. What script What does it do How does this come into play with your UI
2. Downloading what data How are you downloading it
3. What do the above two scenarios have to do with simulating a button click
4. What exactly are the threads for What do you need to run on each thread





Re: Windows Forms General How can simulate button clicking in multiple threads environment£¿

gzcjun

OK,I'll explain corresponding to the questions:

1. What script What does it do How does this come into play with your UI

Now, more and more website began to embed script into button belongs to a form, for example:

<form action="www.test.com/default.aspx">

<input name="city/" type="text">

<input name="startdate/" type="text">

<input name="enddate/" type="text">

<input name="button1" onclick="javascriptTongue Tiedendit();" type="button">

</form>

In this scene, if I use webbrowser, I can get the IHTMLDocument2 interface, and then get the IHTMLInputButtonElement named "button1",all I've to do is like the following:

IHTMLDocument2 pDoc=(IHTMLDocument2)axWebBrowser1.Document;

IHTMLElement btnSubmit=(IHTMLElement)pDoc.all.item("button1",0);

IHTMLInputTextElement inputCity=(IHTMLInputTextElement)pDoc.all.item("city",0);

IHTMLInputTextElement inputCheckInDate=(IHTMLInputTextElement)pDoc.all.item("startdate",0);

IHTMLInputTextElement inputCheckOutDate=(IHTMLInputTextElement)pDoc.all.item("enddate",0);

//do the job

inputCity.value="guangzhou";inputCheckInDate.value="2007-06-15";

inputCheckOutDate.value="2007-06-16";

btnSubmit.click();

With webbrowser, I shouldn¡¯t care about ¡°sendit()¡± script(actually it call another webpage : "www.test.com/search.aspx"), but if I use HttpWebRequest class, the whole thing becomes more complex, I have to analyze the detail script, find what exactly it does.

2. Downloading what data How are you downloading it

The first point has show that I try to post some data to get the result web page.

3. What do the above two scenarios have to do with simulating a button click

I think maybe the first step has shown it.

4. What exactly are the threads for What do you need to run on each thread

My scenario is to supply customer real-time service of tour information: to compare the hotel room price in different website. Because I want to handle the real-time customer inquiry, for example, one customer input like this:city-los angels,startdate:2007-06-15,enddate:2007-06-15 through my website, then I need to download the data from more than 100 website, the number of customers and the websites force me seeking multiple threads. I hope to download just one website¡¯s hotel data in each thread.

So, my question is:

1)I think webbrowser is a good way to resolve complex problem,it's mainly because some buttons contained in the form always have "onclick" or "onmousedown" events handling script,by simulating the button click,I can avoid analyzing the script.From this point,webbrowser seems to be a good choice.

2) The real-time data downloading,as I'd mentioned,I must handle the real-time data download demanding,it seems that multithread is necessary.But I heard that webbrowser doesn't support multithread model.

What should I do to solve the problem, hope to have your help. Thanks.