I'm studying c# and tried other solutions that I've found on stackoverflow.. But I failed..
I'm trying to check if an URL exists when click a button.
When the button is clicked, a progressBar is set to marquee and the verification begins.
But the system stops until the result backs..
Here is the button click:
private void button1_Click(object sender, EventArgs e)
{
this.progressBar1.Style = System.Windows.Forms.ProgressBarStyle.Marquee;
if (RemoteFileExists("http://www.gofdisodfi.com/"))
{
// OK
}
else
{
//FAIL
}
}
And here is the check:
private bool RemoteFileExists(string url)
{
try
{
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "HEAD";
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
return (response.StatusCode == HttpStatusCode.OK);
}
catch
{
return false;
}
}