Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>UI Thread will be freezed when you click <strong>startDownload()</strong>. If you don't want get form freezed, you use <strong>startDownload()</strong> in another thread and make progress updating in cross-threaded. One way,</p> <pre><code>private void startDownload() { Thread thread = new Thread(() =&gt; { WebClient client = new WebClient(); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted); client.DownloadFileAsync(new Uri("http://joshua-ferrara.com/luahelper/lua.syn"), @"C:\LUAHelper\Syntax Files\lua.syn"); }); thread.Start(); } void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { this.BeginInvoke((MethodInvoker) delegate { double bytesIn = double.Parse(e.BytesReceived.ToString()); double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); double percentage = bytesIn / totalBytes * 100; label2.Text = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive; progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString()); }); } void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { this.BeginInvoke((MethodInvoker) delegate { label2.Text = "Completed"; }); } </code></pre> <p>Read more multi-threading in Google like this <a href="http://msdn.microsoft.com/en-us/library/ms951089.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms951089.aspx</a></p> <p>-Fixed missing close ); to the bgThread declaration</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload