System.NET.WebException operation timeout on HttpWebResponse

G

Gary

Problem descriptipn: I have an pocket pc .net app that
implements a System.Threading.Timer periodic process that
goes out to grab for http response from a server. The
app. is implemented in .NET compact framework and runs on
the Pocket PC emulator (Visual Studio .NET 2003). The
elapse value is property set and when I ran the app. in
debug mode, I noted my app. starts to get
System.Net.WebException.Timeout operation after receiving
first two consecutive response are received. When the
timeout operation occurs, all future web queries keep
getting timeout. The timer value is set to "15", which
is converted to 15000. I appreciate if anyone could
explain the situation and help me to solve the issue
here. Please see the following code snippet for details.

Questions:
1. why would the first two web querie always work, but
not on the rest of the query requests?
2. Please advise what I am doing to wrong here and the
correction I need to do.

Code Snippet below -
==========================================================
Imports System
Imports System.Net
Imports System.Xml
Imports System.Threading

Public Class WebQueryProcessor

Private testB As Boolean
Private host As String
Private timerPeriod As Double
Public TimerDelegate As Threading.TimerCallback
Public WebQueryTimer As Threading.Timer

Public Delegate Sub WebQueryReaderEvtTemplate(ByVal
sender As Object, ByVal args As EventArgs)
Public Event MetricDataAvailableEvt As
WebQueryReaderEvtTemplate


Public Sub New(ByVal args As String(), ByVal testB As
Boolean)
MyBase.New()
Me.testB = testB 'always false.
If testB = False Then
host = args(0) 'ignore
End If
timerPeriod = CDbl(args(3)) 'args(3) is set to
15.

TimerDelegate = New Threading.TimerCallback
(AddressOf WebQuery)
WebQueryTimer = New System.Threading.Timer
(TimerDelegate, Nothing, 0, CInt(timerPeriod * 1000))

End Sub

Protected Overridable Sub WebQuery(ByVal state As
Object)
WebQuery()
End Sub

Public Sub WebQuery()
Dim request As WebRequest
Dim response As WebResponse
Dim uri As New Uri("http://www.dell.com")
request = WebRequest.Create(uri)
request.Timeout = 5000
'Set the timeout to five seconds on purpose.
'It shouldn't be taking more than 5 seconds to
process a web query request.
'Also, the first two web queries always work and
then go timeout error on all the rest of query.
response = request.GetResponse
RaiseEvent MetricDataAvailableEvt(Me,
EventArgs.Empty)
End Sub

Public Sub disposeTimer()
Try
WebQueryTimer.Dispose()
Catch ex As Exception
End Try
End Sub

Public Sub stopQueryTimer()
WebQueryTimer.Change(0,
Threading.Timeout.Infinite)
End Sub

Public Sub RestartQueryTimer()
WebQueryTimer.Change(0, CInt(timerPeriod * 1000))
End Sub

End Class
==========================================================
Thanks

Gary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top