Currently I have this code:
public bool checkIfDown(string URL)
{
try
{
//Creating the HttpWebRequest
HttpWebRequest request = WebRequest.Create("http://www." + URL) as HttpWebRequest;
//Setting the Request method HEAD, you can also use GET too.
request.Method = "HEAD";
request.Timeout = 1000;
//Getting the Web Response.
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//Returns TRUE if the Status code == 200
return (response.StatusCode == HttpStatusCode.OK);
}
catch
{
//Any exception will returns false.
return false;
}
}
which checks whether a Domain is Up/Down, but my problem is that the response usually take more than 10 secs to go in catch section.
For example my string domain
is sample123121212.com, the function should return false but it took more than 10 secs.
What I want is to return false
in much shorter time atleast 2 secs, because I need to process atleast 100 domains
.
Any suggestion on how to do this?