I'm able to successfully retrieve a webpage from a web server with a
VB.NET desktop application using (HttpWebRequest/HttpWebResponse), but
when I click the Close button on the application, both it and the
VB.NET debugger hang. I pretty sure I'm closing all the connections
and streams before when this function ends. Any ideas?
If the function below is run before I close the application, then the
application will hang. I have tried the function from 3 different
projects, and only on one of them does the application close without
hanging itself and the debugger.
Public Sub CheckForUpdate()
' objects for writing and reading bytes to streams
Dim objRequest As System.Net.HttpWebRequest
Dim objResponse As System.Net.HttpWebResponse
Dim reader As System.IO.StreamReader
Dim webPage As String
Dim objStream As System.IO.Stream
Try
objRequest =
CType(System.Net.WebRequest.Create("http://192.168.1.102/TBOnline/FileInfo.aspx?version="
& FileVersionInfo.GetVersionInfo("TB.exe").FileVersion),
System.Net.HttpWebRequest)
objResponse =
CType(objRequest.GetResponse,System.Net.HttpWebResponse)
objStream = objResponse.GetResponseStream
reader = New System.IO.StreamReader(objStream)
webPage = reader.ReadToEnd
Catch ex As Exception
MsgBox(ex.Message)
Finally
If Not reader Is Nothing Then reader.Close()
If Not objResponse Is Nothing Then objResponse.Close()
If Not objStream Is Nothing Then objStream.Close()
objResponse.Close()
End Try
End Sub
|