KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I added an event handler to the WebClient's DownloadProgressChanged event, but it never seems to fire. The file successfully downloads, but without having its progress updated. public class DownloadFile { private File file = null; public DownloadFile(File file) { this.file = file; } public void startDownloadThread() { Console.WriteLine("Starting Download : "+file.URL); var t = new Thread(() => DownloadThread(file)); t.Start(); } public Action<string> action_error_downloadFailed = Console.WriteLine; private void DownloadThread(File file) //Unnecessary argument but whatever ;D { try { string url = file.URL; string savepath = file.DestinationDir + "\\" + file.Filename; WebClient_B client = new WebClient_B(); client.Proxy = null; //default to no proxy client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client.DownloadFile(url, savepath); Console.WriteLine("Download finished :" + file.Filename); } catch (Exception ex) { if (action_error_downloadFailed != null) action_error_downloadFailed("Download failed :"+ex.Message); } } private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { try { if (file.TotalSize == 0) file.TotalSize = (int)e.TotalBytesToReceive; file.CurrentSize = (int)e.BytesReceived; Form_DownloadManager.rebuildQueue(); Console.WriteLine("{0} downloaded {1} of {2} bytes. {3} % complete...", (string)e.UserState, e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage); } catch (Exception ex) { Console.WriteLine("client_DownloadPro
Tags (comma-separated)
Save Edits
Cancel