Wednesday 15 August 2012

webclient - C# Download file corrupt -


OK, I am trying to use a file from GitHub using the WebClient C # Class but always corrupt me Got it. This is my code by using {var> client = new webclient ()) {client.DownloadFile ("https://github.com/trapped/rotmg_svr/archive/master .zip ", @" C: /Users/Asus/Desktop/aa.zip "); Client.DownloadProgressChanged + = Changing new download progressing EventHandler (clientDownloadProgressChanged); } Fixed Zero ClientDownload download conversion (Object sender, DownloadProgressingEngenseErgus E) {console.lightline (E.ProgressionTrusting ()); }

//////

  public static void ReadFile () {web client client = new webclient (); Client.DownloadFile ("https://github.com/trapped/rotmg_svr/archive/master.zip", @ "C: /Users/Asus/Desktop/aa.zip"); Client.DownloadProgressChanged + = Changing new download progressing EventHandler (clientDownloadProgressChanged); Client.DownloadFileCompleted + = New System.CommentModel. Async Compatible Event Handler (client_DownloadFileCompleted); } Fixed Zero Client Download File (Object Sender, System.ComponentModel.AsyncCompletedEventArgs E) {Console.WriteLine ("Finished"); } Fixed Zero ClientDownload Prompt Changes (Object Sender, DownloadProgressingEngfectsErg) {Console.Published (E.Progressivs); }   

Now I am using that code and call that function a reader. Readfile (); , File download is good but nothing is written in the console (AD percent). Thank you

Before you set up your event handler, downloadFile () is calling DownloadFile () Call will stop your thread until the file downloads end, which means that those event handlers will not be attached before your file is already downloaded.

You can change the order in this way:

  client.DownloadProgressChanged + = Changing the new download progress eventHandler (client_DownloadProgressChanged); Client.DownloadFileCompleted + = New System.CommentModel. Async Compatible Event Handler (client_DownloadFileCompleted); Client.DownloadFile ("https://github.com/trapped/rotmg_svr/archive/master.zip", @ "C: /Users/Asus/Desktop/aa.zip");   

Or you can use DownloadFileAsync () instead, which will not block your calling thread.

No comments:

Post a Comment