This is not very professional ... and I haven't tested it ...
public delegate void UrlReply(string reply);
private int workingThreads=0;
private urlReply=new UrlReply(this.UrlReply);
private System.Threading.WaitCallback callUrl=new
System.Threading.WaitCallback(this.CallUrl);
public void CheckUrls()
{
foreach (System.Uri url in urlCollection)
{
while (workingThreads>11) Application.DoEvents();
System.Threading.ThreadPool.QueueUserWorkItem(call Url,(object)url);
workingThreads++;
}
}
protected void CallUrl(object state)
{
string reply="Url is ok!";
System.Uri url=(System.Uri)state;
System.Net.WebRequest webRequest=System.Net.WebRequest.Create(url);
try{webRequest.GetResponse();}
catch(System.Exception e){reply=e.Message;}
this.Invoke(this.UrlReply,new object[]{reply});
}
protected void UrlReply(string reply)
{
workingThreads--;
}
"Mahendran" <ma*******@vishwak.com> schrieb im Newsbeitrag
news:uZ*************@TK2MSFTNGP12.phx.gbl...
Hi,
I am designing an window based application which needs to check it up
nearly 2000 url's whether it is valid url or not using WebRequest method.
In this scenario i am using ThreadPool. While using ThreadPool it creates
a thread for each URL.
I need to manage 2000 url's with in 12 threads using ThreadPool.
How do i solve this ?
Thanks in advance
Mahendran