I am getting a timeout error from the following code:
If I call the CheckForNewVersionDebug function once, it works correctly, yet if I call it again, a timeout error occurs.
The following line is not executing in the GetHTTPFileFromWebAddress function:
Why is this happening? Is this just a server issue, or an error in my code?
Code:
Public Function DoesHTTPFileExist(WebAddress As String) As Boolean
Dim HttpWReq As HttpWebRequest = _
CType(WebRequest.Create(WebAddress), HttpWebRequest)
Try
HttpWReq.GetResponse()
Catch x As WebException
Dim Sx As String = x.ToString
If Sx <> "" Then
Return False
End If
End Try
Return True
End Function
Public Function GetHTTPFileFromWebAddress(WebAddress As String) As String
Dim fileinfo As String = ""
Dim myWebReq As Net.HttpWebRequest
myWebReq = Net.WebRequest.Create(WebAddress)
myWebReq.UserAgent = "ie7"
Dim resp As Net.HttpWebResponse = myWebReq.GetResponse
Dim sr As New System.IO.StreamReader(resp.GetResponseStream)
fileinfo = sr.ReadToEnd
myWebReq = Nothing
resp.Close()
sr.Close()
Return fileinfo
End Function
Public Sub CheckForNewVersionDebug()
Dim fileinfo As String
CheckFileVersion:
If DoesHTTPFileExist(stringOnlineVersionLocatonOfFile) Then
fileinfo = GetHTTPFileFromWebAddress(stringOnlineVersionLocatonOfFile)
Else
If DoesHTTPFileExist(stringOnlineVersionLocatonOfFileSecondLink) Then
fileinfo = GetHTTPFileFromWebAddress(stringOnlineVersionLocatonOfFileSecondLink)
Else
Exit Sub
End If
End If
MsgBox(fileinfo)
End Sub
The following line is not executing in the GetHTTPFileFromWebAddress function:
Code:
Dim sr As New System.IO.StreamReader(resp.GetResponseStream)