开发者

accessing multiple web pages at a time using c#

开发者 https://www.devze.com 2022-12-22 14:24 出处:网络
my project need to read multiple web pa开发者_JS百科ges at a time(eg: for a particular keyword google will display 100 pages result maximum)I tried to read that 100 pages using \'for\' loop in URL.But

my project need to read multiple web pa开发者_JS百科ges at a time(eg: for a particular keyword google will display 100 pages result maximum) I tried to read that 100 pages using 'for' loop in URL.But it is showing http request exception in c#.How can i read that pages within sort period of time???


To do it in parallel, push the code onto the ThreadPool. It will not run 100 threads at once (but you don't want that).


this is really nice

http://blogs.msdn.com/somasegar/archive/2009/11/18/reactive-extensions-for-net-rx.aspx http://www.minddriven.de/?p=550

But maybe you can not use RX .


My guess is that you either try to access a disposed object or you don't dispose it, thus leaving too much connections open.

Post some code for more help.


Here is simple solution. But doing so many requests in parallel is very bad, so you have to do some mechanism to reduce number off simultaneous threads.

void QueueWorkItems()
{
    for (int i = 0; i < 10; i++)
        new Action<string>(Request).BeginInvoke("http://www.google.com/search?q=test&start=" + (i * 10), null, null);
}

void Request(string url)
{
    //Process your request
}
0

精彩评论

暂无评论...
验证码 换一张
取 消