Async Await .net 4.5 を使用して非同期的に実行する HTTPHandler 内に長時間実行されるプロセスがあります。
これは期待どおりに完全に機能します...
プロセスに時間がかかりすぎる場合に文字列 'timeout' が返されるように、タイムアウトを追加するにはどうすればよいですか?
Protected Async Sub button1_Click(sender As Object, e As System.EventArgs)
Dim asyncHandler = New AsyncHandler
Await asyncHandler.ProcessRequestAsync(HttpContext.Current)
Response.Write(asyncHandler.Result)
End Sub
Public Class AsyncHandler
Inherits HttpTaskAsyncHandler
Public Property Result As String
Public Async Function ProcessRequestAsync(context As HttpContext) As Task
Me.Result = Await DoLongRunningProcessAsync(context)
End Function
Private Function DoLongRunningProcessAsync(context As HttpContext) As Task(Of String)
'TODO: add a timeout so that if this takes too long we return "timeout":
Return Task.Run(Of String)(Function() DoLongRunningProcess(context))
End Function
Private Function DoLongRunningProcess(context As HttpContext) As String
'perform long running process....
Return "success"
End Function
End Class