Reputation: 128
I am calling this method:
ServicePoint sp = ServicePointManager.FindServicePoint(mRequest.RequestUri, this.MapDataWebProxy);
for getting a service point, but when there is no internet conection available, the method just doesnt return.
Any ideas on how I can prevent this or set a timeout?
Upvotes: 0
Views: 246
Reputation: 29
You can try to verify Internet connection before calling that method. It can be done something like this:
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
//Creating a function that uses the API function...
public static bool IsConnectedToInternet()
{
int Desc;
return InternetGetConnectedState(out Desc, 0);
}
public ServicePoint GetServicePoint()
{
if (!IsConnectedToInternet())
{
return null;
}
return ServicePointManager.FindServicePoint(mRequest.RequestUri, this.MapDataWebProxy);
}
Also Internet can be checked in another way. Without using of "wininet.dll" library: What is the best way to check for Internet connectivity using .NET?
Upvotes: 0