开发者

Set a timeout on webClient.DownloadData?

I'm using a third party url to determine the location of site visitors based on IP address.

I use WebClient.DownloadData() to get the information returned by the url which is a one word answer e.g. as p开发者_高级运维er http://api.hostip.info/country.php

Once I have detected what country the user is in I want to either A) keep them on the current site and store the country in the session or B) redirect them to another countries site.

What I'm worried about is WebClient.DownloadData() hanging so the user is waiting for ages and can't use the site. I'd thought about using DownloadDataAsync but this dosn't seem to be a solution for me as I don't want them to do anything till I find out the country (also see WebClient.DownloadDataAsync is freezing my UI)

Is there a way I can set a timelimit on my call to WebClient.DOwnloadData e.g. if it hasn't returned in 2 seconds, give up?


Looks like HttpWebRequest may be the way to go

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜