11-05-20 03:47 AM
ページ:Run Macro Timeout ステージ:Run Macro Timeout タイプ:エラー アクション:検証 説明:行1のコンパイラエラー:'ExecWithTimeout' は宣言されていません。保護レベルが原因でアクセスできない可能性もあります。 修理可能:いいえ
11-05-20 05:01 AM
' Execute a sub within a specific timeout period ' ' @param timeout The number of seconds to wait before timing out ' @param name The name of the operation ' @param operation The operation to perform Private Sub ExecWithTimeout(timeout As Integer, name As String, operation As Action) Dim ar = operation.BeginInvoke(Nothing, Nothing) If Not ar.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(timeout)) Then Throw New TimeoutException(name & " took more than " & timeout & " secs.") End If operation.EndInvoke(ar) End Sub ' Execute a function within a specific timeout period ' ' @param timeout The number of seconds to wait before timing out ' @param name The name of the operation ' @param operation The operation to perform ' ' @return The result of the operation Private Function ExecWithTimeout(Of T)(timeout As Integer, name As String, operation As Func(Of T)) As T Dim ar = operation.BeginInvoke(Nothing, Nothing) If Not ar.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(timeout)) Then Throw New TimeoutException(name & " took more than " & timeout & " secs.") End If return operation.EndInvoke(ar) End Function
11-05-20 05:56 AM