I have a situation where I’m trying to, from a client-side piece, call off to a server-side piece.
I need to do this synchronously. On my server-side code, though, I’m calling off to another piece of code, which I want to have a maximum of, say, 10 seconds to return a value.
If I don’t have a response within 10 seconds, I want to force my own server piece to set my result equal to 0, and return to the client.
Here’s what I have on my server-side code so far:
Public Function GetWebResult(ByVal inputParameter As Object) As WebReturnObject Implements IWebInterface.GetWebResult
Dim result As New WebReturnObject
Dim webItem As WebItem = Nothing
_timer = New Timers.Timer
AddHandler _timer.Elapsed, AddressOf HandleTimerElapsed
_timer.Interval = 10000 '10 Seconds'
_timer.AutoReset = False
_timer.Start()
webItem = GetAWebItem(inputParameter)
_timer.Stop()
result = webItem
Return result
End Function
Private Sub HandleTimerElapsed(ByVal sender as Object, ByVal e As System.Timers.ElapsedEventArgs) Handles _timer.Elapsed
'result.HasTimedOut = True'
'result.Value = 0'
'How do I then get back into GetWebResult?'
End Sub
I realize this code is not functional. The problem is that I’m unsure how I would go about getting back into GetWebResult to set the appropriate return values before it is sent back to the client.
I’ve already Google’d this problem, and results were scant. The best resources I was able to find were the MSDN documentation on the Timers.Timer class, but even that isn’t terribly useful given my situation.
If anyone has any links, suggestions, etc., I would very much appreciate it.
Call the method asynchronously with a timeout (10 seconds) you’ll be back in
GetWebResultirrespective of the method call completion, then you could return from there. Sample here