G
Guest
I have an application that will be copying pictures (gif & jpg) from a
virtual directory on a server onto a mobile device when the user chooses to
do so. When the pictures begin copying, I sometimes get an error. I can not
recreate the error on my handheld, but it occurs regularly on users handhelds.
With some handhelds, the data was copied without any error.
For example, I get NO errors with the following:
Dell Axim x51v running Windows Mobile 5.0 with Windows XP running IIS 5.1
iPAQ 3800 running PPC 2002 with Windows XP running IIS 5.1
iPAQ (not sure on model) running PPC 2003 with Windows Server 2003 running
IIS 6.0
I get the error with the following (but after successfully copying a few of
many pictures):
IPAQ hx2750 (I believe was running 2003) with Windows Server 2003 running
IIS 6.0
I get the error immediate after it starts downloading with:
HP IPAQ (I believe was running 2003) with Windows Server 2003 running IIS 6.0
All the above have .NET Framework 1.1.
Note that I have not been able to test this with different types of
handhelds with different servers. All of the above items were with different
handhelds and different servers.
There is a try/catch block around the place where the error is happening,
but the catch does not seem to be catching it since I am getting an unhandled
error message.
Note that we are only using the HTTPWeb Request/Response, we are not doing
any winsock level code.
I am encountering the following error, which occurs RIGHT after the handheld
says ‘downloading…’:
ObjectDisposedException
System.Net.Sockets.Socket
Socket::throwIfDisposed+0x19
Socket:oll+0x6
Connection::sendRequest+0x26
WorkItem::doWork+0x36
Timer::ring+0x59
The following is the section of code where the error is happening:
--------- Copy Pictures (portion of code):
'Loop through all students with pictures and download all
available pictures
PictureCountProcessed = 0
PictureCountAdded = 0
For Each StudentDataRow In
StudentData.StudentsWithPictures.Rows
Try
If (Not File.Exists(SelectedLocalPictureDirectory +
StudentDataRow.Item("PictureFile").ToString())) Then
PictureCountProcessed += 1
lblStatus.Text = "Downloading (" +
PictureCountProcessed.ToString() + ") ... " +
StudentDataRow.Item("PictureFile").ToString()
Me.Refresh()
If
(ConnectionData.DownloadFileFromURL(RemotePicturesRootURL +
StudentDataRow.Item("PictureFile").ToString(), SelectedLocalPictureDirectory
+ StudentDataRow.Item("PictureFile").ToString())) Then
PictureCountAdded += 1
End If
End If
Catch ex As Exception
lblStatus.Text = " Downloading (" +
PictureCountProcessed.ToString() + ") ... Picture not found on server."
'Unable to download this picture, keep looping.
'Future: Check for connectivity errors here
End Try
Me.Refresh()
Next
--------- DownloadFileFromURL function:
Public Shared Function DownloadFileFromURL(ByVal RemoteFileURL As
String, ByVal DownloadToLocalFilePath As String) As Boolean
Dim req As HttpWebRequest
Dim res As HttpWebResponse
Dim ReceiveStream As Stream
Dim encode As Encoding
Dim readStream As Stream
Dim writestream As FileStream
Dim read(256) As [Char]
Dim count As Integer
Dim strErrMsg As String
Dim strErrLine As String
Try
' Create a 'WebRequest' object with the specified url
strErrLine = "1 - Create a WebRequest object with the
specified url"
req = CType(WebRequest.Create(RemoteFileURL), HttpWebRequest)
req.Timeout = 60000
' Send the 'WebRequest' and wait for response.
strErrLine = "2 - Send the WebRequest and wait for response."
res = CType(req.GetResponse(), HttpWebResponse)
If res.StatusCode <> HttpStatusCode.OK Then
DownloadFileFromURL = False
strErrMsg = "Connection Problems - " &
res.StatusDescription
Exit Try
End If
' Call method 'GetResponseStream' to obtain stream
associated with the response object
strErrLine = "3 - Call method GetResponseStream"
readStream = res.GetResponseStream()
strErrLine = "6 - Write to Streamwriter"
writestream = New FileStream(DownloadToLocalFilePath,
FileMode.Create, FileAccess.Write)
' Read 256 charcters at a time .
strErrLine = "7 - Read 256 charcters at a time"
Dim BUFFER_SIZE As Integer = 1024
Dim Buffer() As Byte
Buffer = New [Byte](BUFFER_SIZE) {}
count = readStream.Read(Buffer, 0, BUFFER_SIZE)
While (count > 0)
writestream.Write(Buffer, 0, count)
count = readStream.Read(Buffer, 0, BUFFER_SIZE)
End While
writestream.Close()
strErrLine = "8 - Release the resources"
' Release the resources of stream object.
readStream.Close()
DownloadFileFromURL = True
Catch weberrt As WebException
req.Abort()
DownloadFileFromURL = False
strErrMsg = "Web - Error in DownloadFileFromURL - " &
strErrLine & " - " & weberrt.Message
Catch except As Exception
DownloadFileFromURL = False
strErrMsg = "Except - Error in DownloadFileFromURL - " &
strErrLine & " - " & except.Message
Finally
' Release the resources of response object.
If (Not IsNothing(res)) Then
res.Close()
res = Nothing
End If
End Try
End Function
This link shows an exact copy of my situation with no resolution. (I can’t
find other situations on the web).
http://www.error-bank.com/microsoft.public.dotnet.framework.compactframework/54498_Thread.aspx
If it can’t be resolved, what work-around can I do to copy pictures from a
server to a handheld?
virtual directory on a server onto a mobile device when the user chooses to
do so. When the pictures begin copying, I sometimes get an error. I can not
recreate the error on my handheld, but it occurs regularly on users handhelds.
With some handhelds, the data was copied without any error.
For example, I get NO errors with the following:
Dell Axim x51v running Windows Mobile 5.0 with Windows XP running IIS 5.1
iPAQ 3800 running PPC 2002 with Windows XP running IIS 5.1
iPAQ (not sure on model) running PPC 2003 with Windows Server 2003 running
IIS 6.0
I get the error with the following (but after successfully copying a few of
many pictures):
IPAQ hx2750 (I believe was running 2003) with Windows Server 2003 running
IIS 6.0
I get the error immediate after it starts downloading with:
HP IPAQ (I believe was running 2003) with Windows Server 2003 running IIS 6.0
All the above have .NET Framework 1.1.
Note that I have not been able to test this with different types of
handhelds with different servers. All of the above items were with different
handhelds and different servers.
There is a try/catch block around the place where the error is happening,
but the catch does not seem to be catching it since I am getting an unhandled
error message.
Note that we are only using the HTTPWeb Request/Response, we are not doing
any winsock level code.
I am encountering the following error, which occurs RIGHT after the handheld
says ‘downloading…’:
ObjectDisposedException
System.Net.Sockets.Socket
Socket::throwIfDisposed+0x19
Socket:oll+0x6
Connection::sendRequest+0x26
WorkItem::doWork+0x36
Timer::ring+0x59
The following is the section of code where the error is happening:
--------- Copy Pictures (portion of code):
'Loop through all students with pictures and download all
available pictures
PictureCountProcessed = 0
PictureCountAdded = 0
For Each StudentDataRow In
StudentData.StudentsWithPictures.Rows
Try
If (Not File.Exists(SelectedLocalPictureDirectory +
StudentDataRow.Item("PictureFile").ToString())) Then
PictureCountProcessed += 1
lblStatus.Text = "Downloading (" +
PictureCountProcessed.ToString() + ") ... " +
StudentDataRow.Item("PictureFile").ToString()
Me.Refresh()
If
(ConnectionData.DownloadFileFromURL(RemotePicturesRootURL +
StudentDataRow.Item("PictureFile").ToString(), SelectedLocalPictureDirectory
+ StudentDataRow.Item("PictureFile").ToString())) Then
PictureCountAdded += 1
End If
End If
Catch ex As Exception
lblStatus.Text = " Downloading (" +
PictureCountProcessed.ToString() + ") ... Picture not found on server."
'Unable to download this picture, keep looping.
'Future: Check for connectivity errors here
End Try
Me.Refresh()
Next
--------- DownloadFileFromURL function:
Public Shared Function DownloadFileFromURL(ByVal RemoteFileURL As
String, ByVal DownloadToLocalFilePath As String) As Boolean
Dim req As HttpWebRequest
Dim res As HttpWebResponse
Dim ReceiveStream As Stream
Dim encode As Encoding
Dim readStream As Stream
Dim writestream As FileStream
Dim read(256) As [Char]
Dim count As Integer
Dim strErrMsg As String
Dim strErrLine As String
Try
' Create a 'WebRequest' object with the specified url
strErrLine = "1 - Create a WebRequest object with the
specified url"
req = CType(WebRequest.Create(RemoteFileURL), HttpWebRequest)
req.Timeout = 60000
' Send the 'WebRequest' and wait for response.
strErrLine = "2 - Send the WebRequest and wait for response."
res = CType(req.GetResponse(), HttpWebResponse)
If res.StatusCode <> HttpStatusCode.OK Then
DownloadFileFromURL = False
strErrMsg = "Connection Problems - " &
res.StatusDescription
Exit Try
End If
' Call method 'GetResponseStream' to obtain stream
associated with the response object
strErrLine = "3 - Call method GetResponseStream"
readStream = res.GetResponseStream()
strErrLine = "6 - Write to Streamwriter"
writestream = New FileStream(DownloadToLocalFilePath,
FileMode.Create, FileAccess.Write)
' Read 256 charcters at a time .
strErrLine = "7 - Read 256 charcters at a time"
Dim BUFFER_SIZE As Integer = 1024
Dim Buffer() As Byte
Buffer = New [Byte](BUFFER_SIZE) {}
count = readStream.Read(Buffer, 0, BUFFER_SIZE)
While (count > 0)
writestream.Write(Buffer, 0, count)
count = readStream.Read(Buffer, 0, BUFFER_SIZE)
End While
writestream.Close()
strErrLine = "8 - Release the resources"
' Release the resources of stream object.
readStream.Close()
DownloadFileFromURL = True
Catch weberrt As WebException
req.Abort()
DownloadFileFromURL = False
strErrMsg = "Web - Error in DownloadFileFromURL - " &
strErrLine & " - " & weberrt.Message
Catch except As Exception
DownloadFileFromURL = False
strErrMsg = "Except - Error in DownloadFileFromURL - " &
strErrLine & " - " & except.Message
Finally
' Release the resources of response object.
If (Not IsNothing(res)) Then
res.Close()
res = Nothing
End If
End Try
End Function
This link shows an exact copy of my situation with no resolution. (I can’t
find other situations on the web).
http://www.error-bank.com/microsoft.public.dotnet.framework.compactframework/54498_Thread.aspx
If it can’t be resolved, what work-around can I do to copy pictures from a
server to a handheld?