我正在使用Watin从网站自动下载文件。在某些时候,如果Web服务器在特定时间内没有响应,则会发生超时错误。我想知道超时发生的索引以及该索引重复for循环。
例如:
for (int index = 0; index < ros.Count; index++)
{
//download document
FileDownloadHandler down = new FileDownloadHandler(dir+nume+"_"+ro+".pdf");
using (new UseDialogOnce(browser.DialogWatcher, down))
{
down.WaitUntilFileDownloadDialogIsHandled(100);
down.WaitUntilDownloadCompleted(100);
}
}
当超时发生时,我想知道for循环中的索引,我想重试下载处理程序。有可能吗?
答案 0 :(得分:0)
超时很可能会引发异常。你应该弄清楚究竟抛出了哪个异常,然后你可以在循环中捕获它:
for (int index = 0; index < ros.Count; index++)
{
//download document
try
{
FileDownloadHandler down = new FileDownloadHandler(dir+nume+"_"+ro+".pdf");
using (new UseDialogOnce(browser.DialogWatcher, down))
{
down.WaitUntilFileDownloadDialogIsHandled(100);
down.WaitUntilDownloadCompleted(100);
}
}
catch(Exception e)
{
// TODO: Handle timeout. The value of index will tell you when the timeout occured
}
}