Private Sub DownLoadFiles()
myWebClient = New WebClient
AddHandler myWebClient.DownloadProgressChanged, AddressOf ShowDownProgress 这一句是在网上看到的,用这句来捕获下载进度变化事件,不知道对不对。
myWebClient.DownloadFile("http://mir3.clientdown.sdo.com/Mir3/Full_Mir3_Setup_V1.0.0.22.exe", "Full_Mir3_Setup_V1.0.0.22.exe")
End Sub
DownLoadFiles 方法是通过线程启动的,如下:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
downThread = New Thread(AddressOf DownLoadFiles)
downThread.Start()
End Sub
不行,比如像下面这样:
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
ProgressBar1.Value = e.BytesReceived
Label1.Text = e.BytesReceived.ToString
End Sub
我的全部代码如下,很简单的:
Imports System.Net
Imports System.IO
Imports System.Threading
Public Class Form1
Dim downThread As Thread
Dim myWebClient As WebClient
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
downThread = New Thread(AddressOf DownLoadFiles)
downThread.Start()
End Sub
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub DownLoadFiles()
myWebClient = New WebClient
AddHandler myWebClient.DownloadProgressChanged, AddressOf ShowDownProgress
myWebClient.DownloadFile("http://mir3.clientdown.sdo.com/Mir3/Full_Mir3_Setup_V1.0.0.22.exe", "Full_Mir3_Setup_V1.0.0.22.exe")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
downThread.Abort()
End Sub
Dim myWebClient As WebClient
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myWebClient = New WebClient
AddHandler myWebClient.DownloadProgressChanged, AddressOf ShowDownProgress '这一句是在网上看到的,用这句来捕获下载进度变化事件,不知道对不对。
AddHandler myWebClient.DownloadDataCompleted, AddressOf DownloadDataCompleted
End Sub
Private Sub DownLoadFiles()
myWebClient.DownloadFileAsync(New Uri("http://dlsw.baidu.com/sw-search-sp/soft/3a/12350/QQ_V7.6.15742.0_setup.1441010663.exe"), "QQ_V7.6.15742.0_setup.1441010663.exe")
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
DownLoadFiles()
End Sub
'这里是进度条显示
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
Invoke(New Action(Of Integer)(Sub(i) ProgressBar1.Value = i), e.ProgressPercentage)
End Sub
'这里是完成部分
Sub DownloadDataCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
If MessageBox.Show("您已经下载成功,是否打开应用程序?", "提示", MessageBoxButtons.YesNo) = DialogResult.Yes Then
Dim myWebClient As WebClient
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myWebClient = New WebClient
AddHandler myWebClient.DownloadProgressChanged, AddressOf ShowDownProgress '这一句是在网上看到的,用这句来捕获下载进度变化事件,不知道对不对。
AddHandler myWebClient.DownloadDataCompleted, AddressOf DownloadDataCompleted
End Sub
Private Sub DownLoadFiles()
myWebClient.DownloadFileAsync(New Uri("http://dlsw.baidu.com/sw-search-sp/soft/3a/12350/QQ_V7.6.15742.0_setup.1441010663.exe"), "QQ_V7.6.15742.0_setup.1441010663.exe")
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
DownLoadFiles()
End Sub
'这里是进度条显示
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
Invoke(New Action(Of Integer)(Sub(i) ProgressBar1.Value = i), e.ProgressPercentage)
End Sub
'这里是完成部分
Sub DownloadDataCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
If MessageBox.Show("您已经下载成功,是否打开应用程序?", "提示", MessageBoxButtons.YesNo) = DialogResult.Yes Then
'这里是进度条显示
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
ProgressBar1.Value = e.ProgressPercentage
End Sub
不行,比如像下面这样:
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
ProgressBar1.Value = e.BytesReceived
Label1.Text = e.BytesReceived.ToString
End Sub
不行,比如像下面这样:
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
ProgressBar1.Value = e.BytesReceived
Label1.Text = e.BytesReceived.ToString
End Sub
我的全部代码如下,很简单的:
Imports System.Net
Imports System.IO
Imports System.Threading
Public Class Form1
Dim downThread As Thread
Dim myWebClient As WebClient
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
downThread = New Thread(AddressOf DownLoadFiles)
downThread.Start()
End Sub
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub DownLoadFiles()
myWebClient = New WebClient
AddHandler myWebClient.DownloadProgressChanged, AddressOf ShowDownProgress
myWebClient.DownloadFile("http://mir3.clientdown.sdo.com/Mir3/Full_Mir3_Setup_V1.0.0.22.exe", "Full_Mir3_Setup_V1.0.0.22.exe")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
downThread.Abort()
End Sub
End Class
老师们帮我看看我要如何得到即时下载的进度?
#7
#5
我的全部代码如下,很简单的:
Imports System.Net
Imports System.IO
Imports System.Threading
Public Class Form1
Dim downThread As Thread
Dim myWebClient As WebClient
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
downThread = New Thread(AddressOf DownLoadFiles)
downThread.Start()
End Sub
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub DownLoadFiles()
myWebClient = New WebClient
AddHandler myWebClient.DownloadProgressChanged, AddressOf ShowDownProgress
myWebClient.DownloadFile("http://mir3.clientdown.sdo.com/Mir3/Full_Mir3_Setup_V1.0.0.22.exe", "Full_Mir3_Setup_V1.0.0.22.exe")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
downThread.Abort()
End Sub
Dim myWebClient As WebClient
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myWebClient = New WebClient
AddHandler myWebClient.DownloadProgressChanged, AddressOf ShowDownProgress '这一句是在网上看到的,用这句来捕获下载进度变化事件,不知道对不对。
AddHandler myWebClient.DownloadDataCompleted, AddressOf DownloadDataCompleted
End Sub
Private Sub DownLoadFiles()
myWebClient.DownloadFileAsync(New Uri("http://dlsw.baidu.com/sw-search-sp/soft/3a/12350/QQ_V7.6.15742.0_setup.1441010663.exe"), "QQ_V7.6.15742.0_setup.1441010663.exe")
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
DownLoadFiles()
End Sub
'这里是进度条显示
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
Invoke(New Action(Of Integer)(Sub(i) ProgressBar1.Value = i), e.ProgressPercentage)
End Sub
'这里是完成部分
Sub DownloadDataCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
If MessageBox.Show("您已经下载成功,是否打开应用程序?", "提示", MessageBoxButtons.YesNo) = DialogResult.Yes Then
Dim myWebClient As WebClient
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myWebClient = New WebClient
AddHandler myWebClient.DownloadProgressChanged, AddressOf ShowDownProgress '这一句是在网上看到的,用这句来捕获下载进度变化事件,不知道对不对。
AddHandler myWebClient.DownloadDataCompleted, AddressOf DownloadDataCompleted
End Sub
Private Sub DownLoadFiles()
myWebClient.DownloadFileAsync(New Uri("http://dlsw.baidu.com/sw-search-sp/soft/3a/12350/QQ_V7.6.15742.0_setup.1441010663.exe"), "QQ_V7.6.15742.0_setup.1441010663.exe")
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
DownLoadFiles()
End Sub
'这里是进度条显示
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
Invoke(New Action(Of Integer)(Sub(i) ProgressBar1.Value = i), e.ProgressPercentage)
End Sub
'这里是完成部分
Sub DownloadDataCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
If MessageBox.Show("您已经下载成功,是否打开应用程序?", "提示", MessageBoxButtons.YesNo) = DialogResult.Yes Then
'这里是进度条显示
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
ProgressBar1.Value = e.ProgressPercentage
End Sub