【问题标题】:How to Catch StriptTimeOut in Asp.Net so I can restart or bail a loop如何在 Asp.Net 中捕获 StriptTimeOut,以便我可以重新启动或保释循环
【发布时间】:2013-11-08 17:37:43
【问题描述】:

我有一个非常密集的函数,在一系列数据上运行一个循环。

它很少使用,但我需要能够捕获任何 TimeOut 错误并安排重新启动。

有什么办法吗?

或者我只需将ScriptTimeout 设置为一些愚蠢的东西?

【问题讨论】:

  • 能贴出相关代码吗?又是怎么称呼的?

标签: asp.net vb.net timeout


【解决方案1】:

不知道您在做什么或您的代码是什么样的,但这里有一个示例,在捕获错误时最多运行 10 次。您应该只针对某些错误执行此操作,例如超时错误,而不是所有错误,如此处所示。

Dim bSuccess as boolean = false
Dim iLoop as byte = 0
do while not bSuccess
  iLoop += 1
  Try
    ..Your code/method here
    bSuccess = true
  Catch ex as Exception
    'Check for max number of retries
    If iloop >= 10 then
      ..What do you want to do, bSuccess = true, Exit Do, Exit Sub, Throw ex, etc
    End if
    'Check if certain type of error to get out of loop
  End Try
loop

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-18
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    相关资源
    最近更新 更多