110,500
社区成员
发帖
与我相关
我的任务
分享
var webClient = new HtmlWeb();
var html = webClient.Load(url);
try{var html = webClient.Load(url);}
async Task<string> geturl(string url, CancellationToken token, int count = 3)
{
CancellationTokenSource _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token);
for (int i = 0; i < count; i++)
{
//外部放弃条件条件,比如主动放弃,比如设定最大等待时间
_cancellationTokenSource.Token.ThrowIfCancellationRequested();
HttpClient client = new HttpClient();
try
{
var s = await client.GetStringAsync(url);
return s;
}
catch (Exception e)
{
}
}
throw new TimeoutException("3重试未响应");
}
HtmlDocument html = new HtmlDocument();
int cnt=0;
do
{
try { html = webClient.Load(url); cnt=10; }
catch (Exception e) { cnt++; }
} while (cnt<3);
HtmlDocument html = new HtmlDocument();
Boolean b;
do
{
try { html = webClient.Load(url); b = true; }
catch (Exception e) { b = false; }
} while (b == false);
[/quote]