This is my code:
string Url = "http://illution.dk/";
WebClient Http = new WebClient();
Http.DownloadStringAsync(new Uri(Url));
Http.DownloadStringCompleted += new DownloadStringCompletedEventHandler(GetModelTypeResponse);
If I run this on a machine with no internet connection an error will be thrown. “Hostname could not be resolved”
Is there any way I can remove this error message? Or check if there isn’t an internet connection?
Edit 1
try
{
ComputerInfo ComputerInfoComp = new ComputerInfo();
string Url = "http://illution.dk/"
WebClient Http = new WebClient();
Http.DownloadStringAsync(new Uri(Url));
Http.DownloadStringCompleted += new DownloadStringCompletedEventHandler(GetModelTypeResponse);
ComputerInfoComp = null;
}
catch (System.Net.WebException e)
{
//
}
Check
e.Errorin yourGetModelTypeResponsehandler method. Ife.Erroris of typeWebExceptionthen checkwebException.Statusvalue. The value will beWebExceptionStatus.NameResolutionFailurein case of “Hostname could not be resolved” exception