A more simpler if thats to confusing
vb Code:
Imports System.Net Public Class MainForm Private ReadOnly temp As String = "http://download.piriform.com/ccsetup327.exe" Private m_dictionary As New Dictionary(Of WebClient, String) Private Sub Download(ByVal Path As String, ByVal FileName As String) Dim client As New WebClient Dim file As String = IO.Path.Combine(Path, FileName) AddHandler client.DownloadProgressChanged, AddressOf DownloadProgressChanged AddHandler client.DownloadFileCompleted, AddressOf DownloadFileCompleted client.DownloadFileAsync(New Uri(temp), file) Me.m_dictionary.Add(client, file) End Sub Private Sub DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Dim file As String = m_dictionary.Item(CType(sender, WebClient)) Me.RichTextBox1.AppendText(String.Format("File {0} {1}{2}", file, e.ProgressPercentage & "%", vbNewLine)) Me.RichTextBox1.ScrollToCaret() End Sub Private Sub DownloadFileCompleted(ByVal sender As Object, _ ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Dim client As WebClient = DirectCast(sender, WebClient) client.Dispose() m_dictionary.Remove(client) End Sub End Class




Reply With Quote
