【发布时间】:2024-01-20 16:34:01
【问题描述】:
我正在尝试获取大约的文档类型。 3k 链接。但是当它到达 700-900 标记线时,我总是会遇到异常。
我怎样才能在异常发生的地方继续(所以我没有义务再次从零开始)?这可能吗?
这是我使用的代码:
try
{
Parallel.ForEach(linkList, link =>
{
stopwatch.Restart();
Console.Write($"Downloading page {index++} of {linkList.Count}...");
documents.Add(LoadPage(link));
Console.Write($" in {stopwatch.Elapsed.TotalMilliseconds} ms");
Console.WriteLine();
});
return documents;
}
catch (Exception e)
{
???
}
【问题讨论】:
-
你有没有想过将 try-catch 移动到 inside 并行循环中?
标签: c# exception web-scraping try-catch parallel.foreach