Note that there are some explanatory texts on larger screens.

plurals
  1. POBackgroundworker is always busy
    primarykey
    data
    text
    <p>I'm new to using event handlers and backgroundworkers, so I may be missing something completely obvious here. Still, I've been trying to fix this for two days, so I thought I might as well see what anyone had to say.</p> <p>I have a backgroundworker called SqlExpressDownloader. It starts running at the beginning of my program, the rest of the work runs, and then it should wait for the operations in the <code>SqlExpressDownloader_DoWork()</code> method to complete before continuing. The only problem is that for some reason whenever I do <code>while(SqlExpressDownloader.IsBusy)</code>, it always responds as busy and therefore will wait forever. </p> <p>The code for the event handler is here:</p> <pre><code> private void SqlExpressDownloader_DoWork(object sender, DoWorkEventArgs e) { string sSource = string.Format("{0}\\{1}", Paths.Settings_Common, "sqlexpr_x64_enu.exe"); Debug.WriteLine(sSource); Debug.WriteLine("http://www.elexioamp.com/Install/redistributables/sql2008r2express/sqlexpr_x64_enu.exe"); if (!System.IO.File.Exists(sSource)) { WebClient oWebClient = new WebClient(); oWebClient.DownloadProgressChanged += DownloadProgressChanged; oWebClient.DownloadDataCompleted += DownloadComplete; oWebClient.DownloadFileAsync(new System.Uri("http://www.elexioamp.com/Install/redistributables/sql2008r2express/sqlexpr_x64_enu.exe"), sSource); while (oWebClient.IsBusy) { Thread.Sleep(100); } e.Result = ""; DownloadFinished = true; } } </code></pre> <p>I have watched the code and have watched it complete this method. I even added a <code>return</code> after the <code>DownloadFinished = true</code>, but it still responds as busy. What I want to know is how to make the backgroundworker respond as not busy. </p> <p>EDIT The events are all added in the constructor as shown here:</p> <pre><code> SqlExpressDownloader = new BackgroundWorker(); SqlExpressDownloader.DoWork += new DoWorkEventHandler(this.SqlExpressDownloader_DoWork); SqlExpressDownloader.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.SqlExpressDownloader_RunWorkerCompleted); </code></pre> <p>The <code>RunWorkerCompleteEventHandler</code> looks like this:</p> <pre><code> private void SqlExpressDownloader_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { Debug.WriteLine("The actions are complete."); } else { Debug.WriteLine("Error in completed work."); } } </code></pre> <p>But, when I debugged it last, it didn't actually trigger.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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