Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have a bug in my updater, code here >
after download first file download is stop :(
have some ideea ?
VB
Private Sub BackgroundWorker2_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork
        Dim linkdl As String
        linkdl = "http://s3.amazonaws.com/MinecraftDownload/"
        Dim dirminecraft12 As String
        dirminecraft12 = (GetFolderPath(SpecialFolder.ApplicationData) & "/.minecraft/bin\")

        Dim filepaths As String()
        filepaths = {"minecraft.jar", "jinput.jar", "lwjgl.jar", "lwjgl_util.jar", "windows_natives.jar"}


        For Each filePath In filepaths
            'Creating the request and getting the response
            Dim theResponse As HttpWebResponse
            Dim theRequest As HttpWebRequest

            theRequest = WebRequest.Create(linkdl & filePath)
            theResponse = theRequest.GetResponse

            Dim length As Long = theResponse.ContentLength 'Size of the response (in bytes)

            Dim safedelegate As New ChangeTextsSafe(AddressOf ChangeTexts2)
            Me.Invoke(safedelegate, length, 0, 0, 0) 'Invoke the TreadsafeDelegate
            Dim writeStream As New IO.FileStream(dirminecraft12 + filePath, IO.FileMode.Create)

            'Replacement for Stream.Position (webResponse stream doesn't support seek)
            Dim nRead As Integer

            'To calculate the download speed
            Dim speedtimer As New Stopwatch
            Dim currentspeed As Double = -1
            Dim readings As Integer = 0

            Do

                speedtimer.Start()

                Dim readBytes(4095) As Byte
                Dim bytesread As Integer = theResponse.GetResponseStream.Read(readBytes, 0, 4096)

                nRead += bytesread
                Dim percent As Integer = (nRead / length) * 100

                Me.Invoke(safedelegate, length, nRead, percent, currentspeed)

                If bytesread = 0 Then Exit Do

                writeStream.Write(readBytes, 0, bytesread)

                speedtimer.Stop()
                readings += 1
                If readings >= 5 Then 'For increase precision, the speed it's calculated only every five cicles
                    currentspeed = 20480 / (speedtimer.ElapsedMilliseconds / 1000)
                    speedtimer.Reset()
                    readings = 0
                End If

            Loop
            'Close the streams
            theResponse.GetResponseStream.Close()
            writeStream.Close()

            Dim completeDelegate2 As New DownloadCompleteSafe(AddressOf DownloadComplete2)
            Me.Invoke(completeDelegate2, False)
        Next
    End Sub
Posted
Comments
ZurdoDev 12-Oct-12 8:12am    
Have you stepped through the code? What is happening?
Malasuerte94 12-Oct-12 8:36am    
Value of '2015' is not valid for 'Value'. 'Value' should be between 'minimum' and 'maximum'.
Parameter name: Value
here is error
Me.Invoke(safedelegate, length, nRead, percent, currentspeed)
Sergey Alexandrovich Kryukov 12-Oct-12 14:24pm    
OK, continue please. What are the min/max values, in what lines of code, what happens next? I think if you go forward, you can solve your problem by yourself.
--SA
ExcelledProducts 14-Oct-12 14:24pm    
I think its because a background worker does not loop. You need to create a loop around the whole background worker or just use a timer.
ExcelledProducts 9-Nov-12 9:40am    
down use a bte stream. Use a webclient. Dim wc As New WebClient.

1 solution

To download the files, you can do this:
VB
Dim linkdl As String = "http://s3.amazonaws.com/MinecraftDownload/"
Dim filepaths As String() = New String() {"minecraft.jar", "jinput.jar", "lwjgl.jar", "lwjgl_util.jar", "windows_natives.jar"}
For Each filePath As String In filepaths
	Dim webClient As New WebClient()
	webClient.DownloadFile(linkdl & filePath, dirminecraft12 & filePath)
                ' download the file
		' save the file to the specified path
Next

More about the WebClient.DownloadFile method[^]

Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900