为什么下载会停止? [英] Why downloading do stop ?

查看:70
本文介绍了为什么下载会停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的更新程序中有错误,请在此处进行代码>
下载后,第一个文件下载停止:(
有一些想法吗?

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

推荐答案

要下载文件,您可以执行以下操作:
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.


这篇关于为什么下载会停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆