Note that there are some explanatory texts on larger screens.

plurals
  1. POBackground Worker reports busy despite been cancelled and no longer present
    primarykey
    data
    text
    <p>When I cancel and dispose of my background worker, despite it disappearing from the VS threads list it continues to report busy to my application which is waiting for it to close. Also my RunWorkerCompleted event is never raised. </p> <p>Debugging shows that the code is exited with no further pending execution that I can see. </p> <p>If I remove the .IsBusy check, VS reports that "This BackgroundWorker is currently busy and cannot run multiple tasks concurrently"</p> <p>I cannot understand why the thread which is no longer listed in VS continues to operate after closing. </p> <pre><code> private void UpdateTimeLine() { txtb_timeline.Text = "Updating..."; startTimelineUpdater.DoWork += new DoWorkEventHandler(startTimelineUpdater_DoWork); startTimelineUpdater.RunWorkerAsync("hometimeline"); startTimelineUpdater.WorkerReportsProgress = true; startTimelineUpdater.ProgressChanged += new ProgressChangedEventHandler (startTimelineUpdater_ProgressChanged); startTimelineUpdater.WorkerSupportsCancellation = true; } void startTimelineUpdater_DoWork(object sender, DoWorkEventArgs e) { //begin the thread to maintain updates of SQL beginRegUpdateTimeline.DoWork += new DoWorkEventHandler(beginRegUpdateTimeline_DoWork); beginRegUpdateTimeline.RunWorkerAsync(); beginRegUpdateTimeline.WorkerSupportsCancellation = true; while (true) { List&lt;string[]&gt; sqlset; Xtweet getSQL = new Xtweet(); if(e.Argument.ToString() == "hometimeline") { sqlset = getSQL.CollectLocalTimelineSql(); } else { sqlset = getSQL.CollectLocalTimelineSql(Int64.Parse(e.Argument.ToString())); } int i = 0; while (i &lt; 10) { foreach (var stringse in sqlset) { StringBuilder sb = new StringBuilder(); sb.Append(stringse[0]); sb.Append(": "); sb.Append(stringse[1]); sb.Append(" @ "); sb.Append(stringse[2]); sb.Append("\n"); BackgroundWorker bkgwk = sender as BackgroundWorker; bkgwk.ReportProgress(0, sb.ToString()); Thread.Sleep(1000); i++; if(startTimelineUpdater.CancellationPending) { e.Cancel = true; startTimelineUpdater.Dispose(); break; } } if (e.Cancel == true) { break; } } if (e.Cancel == true) { break; } } } /// &lt;summary&gt; /// Handles the DoWork event of the beginRegUpdateTimeline control. /// Updates the timeline sql on a regular basis /// &lt;/summary&gt; /// &lt;param name="sender"&gt;The source of the event.&lt;/param&gt; /// &lt;param name="e"&gt;The &lt;see cref="System.ComponentModel.DoWorkEventArgs"/&gt; instance containing the event data.&lt;/param&gt; void beginRegUpdateTimeline_DoWork(object sender, DoWorkEventArgs e) { while (true) { //update time in seconds int secs = 10; Xtweet.PreSqlDataCollection(null,null); Thread.Sleep(secs*1000); if(beginRegUpdateTimeline.CancellationPending) { e.Cancel = true; beginRegUpdateTimeline.Dispose(); break; } } } private void startTimelineUpdater_ProgressChanged(object sender, ProgressChangedEventArgs e) { txtb_timeline.Text = e.UserState.ToString(); } </code></pre>
    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