public delegate void AnonymousHandler();

/// <summary>
/// 重试某过程 maxError 次,直到成功或失败
/// </summary>
/// <param name="handler">托管函数</param>
/// <param name="maxError">允许失败的次数</param>
/// <returns>如果执行成功,则返回 null, 否则返回该错误对象</returns>
public static Exception Trys(AnonymousHandler handler, int maxError) {
if (handler != null) {
Exception ex = null;
for (int a = 0; a < maxError; a++) {
try {
handler();
return null;
} catch (Exception e) {
ex = e;
}
}
return ex;
}
return null;
}

ex = Lib.Trys(delegate()
{
ie.Action = url;
ie.CookieContainer = new CookieContainer();
ie.AcceptLanguage = "zh-cn,zh;q=0.5";
ie.CookieContainer.SetCookies(ie.Address, "Culture=zh-hk");
ie.Send();
Thread.CurrentThread.Join(100);
}, 10);

相关文章:

  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2022-01-01
  • 2021-12-12
  • 2021-09-27
  • 2022-01-13
  • 2021-11-29
猜你喜欢
  • 2021-10-07
  • 2021-04-16
  • 2022-02-28
  • 2022-12-23
  • 2021-12-29
  • 2021-07-06
  • 2021-12-26
相关资源
相似解决方案