Click here to Skip to main content
12,501,082 members (40,426 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB10.0 VB.NET
Hi i have a bug in my updater, code here >
after download first file download is stop :(
have some ideea ?
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 12-Oct-12 1:28am
Comments
ryanb31 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
Member 9210249 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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

To download the files, you can do this:
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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160919.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100