EDN Admin
Well-known member
I got two issues getting my application to download a file. One small and one rather big.
<span style="text-decoration:underline Small: <br/>
The downloader seems to have an issue using the users full download capability while the downloaded size is under 1 MB. As soon as it hits that, it seems to speed up with 10-100 times the previous speed.
(Snippet at the end of the post)
<span style="text-decoration:underline Big: <br/>
It seems to have to do with the filesize, which is about 5GB. As soon as my application hits about 1GB it completely locks up. (Without an error message, which I do have built in with a try...catch statement)<br/>
I actually have to force quit the app to make it stop.<br/>
It works perfectly fine with a 20MB file.
I have the idea its because of the int64s I use. But I need to use those (afaik) due to the big file size.
My download function:
<br/>
<pre lang="x-vbnet Public Function funcDownload(ByVal client As Boolean) As Boolean
Dim FS As FileStream
Try
funcLog("Starting...", Method.eAction, SubActionEvent.eDownload, Message.eNo)
Dim wRemote As WebRequest
Dim bBuffer As Byte()
ReDim bBuffer(256)
Dim iBytesRead As Integer
Dim iTotalBytesRead As Integer
if client is false, it attempts to download the update.
If client = False Then
funcLog("Update", Method.eAction, SubActionEvent.eDownload, Message.eNo)
File.Delete(Application.StartupPath & "" & launcherName & ".zip")
FS = New FileStream(Application.StartupPath & "" & launcherName & ".zip", FileMode.Create, FileAccess.ReadWrite)
wRemote = WebRequest.Create(websiteUrl & launcherName & ".zip")
Else if client is true, it will attempt to download the client itself
funcLog("Client", Method.eAction, SubActionEvent.eDownload, Message.eNo)
FS = New FileStream(Application.StartupPath & "" & clientName & ".zip", FileMode.Create, FileAccess.ReadWrite)
wRemote = WebRequest.Create(websiteUrl & clientName & ".zip")
End If
Dim myWebResponse As WebResponse = wRemote.GetResponse
RaiseEvent DownloadSizeObtained(myWebResponse.ContentLength)
Dim sChunks As Stream = myWebResponse.GetResponseStream
Do
iBytesRead = sChunks.Read(bBuffer, 0, 256)
FS.Write(bBuffer, 0, iBytesRead)
iTotalBytesRead += iBytesRead
If myWebResponse.ContentLength < iTotalBytesRead Then
RaiseEvent DownloadAmountChanged(myWebResponse.ContentLength)
Else
RaiseEvent DownloadAmountChanged(iTotalBytesRead)
End If
Loop While Not iBytesRead = 0
sChunks.Close()
FS.Close()
If it was succesful, itll call this event. Otherwise it will skip to "catch ex as exception" and will throw an error in a messagebox
RaiseEvent DownloadComplete()
Return True
Catch ex As Exception
RaiseEvent DownloadFailed(ex)
Return False
End Try
End Function[/code]
<br/>
My downloadAmounChanged Function:
<div style="color:Black; background-color:White
<pre> <span style="color:Blue Private
<span style="color:Blue Sub
_Downloader_funcDownloadAmountChanged(<span style="color:Blue ByVal
iNewProgress <span style="color:Blue As
<span style="color:Blue Long
) <span style="color:Blue Handles
_Downloader.DownloadAmountChanged
<span style="color:Green Sets the progressbar value to the currently downloaded amount.
pbDownload.Value = (Convert.ToInt64(iNewProgress) / 100)
<span style="color:Blue Dim
percentDownloaded <span style="color:Blue As
<span style="color:Blue Integer
= (pbDownload.Value / pbDownload.Maximum) * 100
lblDownloaded.Text = <span style="color:#a31515 "Downloaded: "
& UpdaterClass.funcUpdateFileSize(iNewProgress) & <span style="color:#a31515 "/"
& UpdaterClass.funcUpdateFileSize(totalFileSize) & <span style="color:#a31515 " ("
& percentDownloaded & <span style="color:#a31515 "%)"
lblStatus.Text = <span style="color:#a31515 "Downloading..."
Application.DoEvents()
<span style="color:Blue End
<span style="color:Blue Sub
[/code]
Dalek
View the full article
<span style="text-decoration:underline Small: <br/>
The downloader seems to have an issue using the users full download capability while the downloaded size is under 1 MB. As soon as it hits that, it seems to speed up with 10-100 times the previous speed.
(Snippet at the end of the post)
<span style="text-decoration:underline Big: <br/>
It seems to have to do with the filesize, which is about 5GB. As soon as my application hits about 1GB it completely locks up. (Without an error message, which I do have built in with a try...catch statement)<br/>
I actually have to force quit the app to make it stop.<br/>
It works perfectly fine with a 20MB file.
I have the idea its because of the int64s I use. But I need to use those (afaik) due to the big file size.
My download function:
<br/>
<pre lang="x-vbnet Public Function funcDownload(ByVal client As Boolean) As Boolean
Dim FS As FileStream
Try
funcLog("Starting...", Method.eAction, SubActionEvent.eDownload, Message.eNo)
Dim wRemote As WebRequest
Dim bBuffer As Byte()
ReDim bBuffer(256)
Dim iBytesRead As Integer
Dim iTotalBytesRead As Integer
if client is false, it attempts to download the update.
If client = False Then
funcLog("Update", Method.eAction, SubActionEvent.eDownload, Message.eNo)
File.Delete(Application.StartupPath & "" & launcherName & ".zip")
FS = New FileStream(Application.StartupPath & "" & launcherName & ".zip", FileMode.Create, FileAccess.ReadWrite)
wRemote = WebRequest.Create(websiteUrl & launcherName & ".zip")
Else if client is true, it will attempt to download the client itself
funcLog("Client", Method.eAction, SubActionEvent.eDownload, Message.eNo)
FS = New FileStream(Application.StartupPath & "" & clientName & ".zip", FileMode.Create, FileAccess.ReadWrite)
wRemote = WebRequest.Create(websiteUrl & clientName & ".zip")
End If
Dim myWebResponse As WebResponse = wRemote.GetResponse
RaiseEvent DownloadSizeObtained(myWebResponse.ContentLength)
Dim sChunks As Stream = myWebResponse.GetResponseStream
Do
iBytesRead = sChunks.Read(bBuffer, 0, 256)
FS.Write(bBuffer, 0, iBytesRead)
iTotalBytesRead += iBytesRead
If myWebResponse.ContentLength < iTotalBytesRead Then
RaiseEvent DownloadAmountChanged(myWebResponse.ContentLength)
Else
RaiseEvent DownloadAmountChanged(iTotalBytesRead)
End If
Loop While Not iBytesRead = 0
sChunks.Close()
FS.Close()
If it was succesful, itll call this event. Otherwise it will skip to "catch ex as exception" and will throw an error in a messagebox
RaiseEvent DownloadComplete()
Return True
Catch ex As Exception
RaiseEvent DownloadFailed(ex)
Return False
End Try
End Function[/code]
<br/>
My downloadAmounChanged Function:
<div style="color:Black; background-color:White
<pre> <span style="color:Blue Private
<span style="color:Blue Sub
_Downloader_funcDownloadAmountChanged(<span style="color:Blue ByVal
iNewProgress <span style="color:Blue As
<span style="color:Blue Long
) <span style="color:Blue Handles
_Downloader.DownloadAmountChanged
<span style="color:Green Sets the progressbar value to the currently downloaded amount.
pbDownload.Value = (Convert.ToInt64(iNewProgress) / 100)
<span style="color:Blue Dim
percentDownloaded <span style="color:Blue As
<span style="color:Blue Integer
= (pbDownload.Value / pbDownload.Maximum) * 100
lblDownloaded.Text = <span style="color:#a31515 "Downloaded: "
& UpdaterClass.funcUpdateFileSize(iNewProgress) & <span style="color:#a31515 "/"
& UpdaterClass.funcUpdateFileSize(totalFileSize) & <span style="color:#a31515 " ("
& percentDownloaded & <span style="color:#a31515 "%)"
lblStatus.Text = <span style="color:#a31515 "Downloading..."
Application.DoEvents()
<span style="color:Blue End
<span style="color:Blue Sub
[/code]
Dalek
View the full article