Note that there are some explanatory texts on larger screens.

plurals
  1. POSynchronizationContext.Post not working inside BackgroundWorker
    primarykey
    data
    text
    <p>I'm using a background-worker to do all of my processing. Inside there, I have many places where I write to my "log" text box. All of those work great, but at the end of the background-worker, the very last line, I have one more call via <code>SynchronizationContext</code> that doesn't fire. Why do all of the other calls work, and not the last one?</p> <p>I should add that the application just "hangs", and there's even an EventLog entry saying:</p> <pre> The program MVST.CodeSync.exe version 2.0.0.0 stopped interacting with Windows and was closed. To see if more information about the problem is available, check the problem history in the Action Center control panel. Process ID: 1f5c Start Time: 01ccc0e2e7ca1d42 Termination Time: 16 Application Path: C:\Users\ganders\Desktop\NewCodeSync\MVST.CodeSync.exe Report Id: 629f3533-2cd6-11e1-9e15-005056b75254 </pre> <p>Here's the <code>DoWork</code> method (which is executed when calling <code>RunWorkerAsync</code>):</p> <pre><code>private void bgw_StartCompare(object sender, DoWorkEventArgs e) { OnWriteLogArgs args = null; CompareData compareData = e.Argument as CompareData; // We need to iterate through all of the nodes and if they are checked, continue foreach (TreeNode subSystemNode in compareData.TreeNodes) { if (!subSystemNode.Checked) continue; args = new OnWriteLogArgs(String.Format("-------------------------- Comparing sub-system: \"{0}\" with CompareType: \"{1}\" --------------------------", subSystemNode.Text, compareData.CompareType)); syncContext.Post(delegate { OnWriteLog(args); }, null); // Each of these nodes should be a server, so continue foreach (TreeNode serverNode in subSystemNode.Nodes) { if (!serverNode.Checked) continue; args = new OnWriteLogArgs(String.Format("-------------------------- Comparing server: \"{0}\" with CompareType: \"{1}\" --------------------------", serverNode.Text, compareData.CompareType)); syncContext.Post(delegate { OnWriteLog(args); }, null); // The "tag" contains the server information that we need to do the comparison CustomConfig.Server server = (CustomConfig.Server)serverNode.Tag; if (!compareData.DoneInitialCompare) CompareAll(compareData, server, string.Empty, server.CompareBasePath, serverNode, compareData.CompareType); else CompareAllByTreeNode(compareData, server, serverNode, compareData.CompareType); } } syncContext.Post(delegate { OnWriteLog(new OnWriteLogArgs("Finished the compare...")); }, null); RebuildTreeViewArgs rArgs = new RebuildTreeViewArgs(compareData.OnlyShowDifferences, compareData.TreeNodes); syncContext.Post(delegate { OnRebuildTreeView(rArgs); }, null); MessageBox.Show("It made it..."); syncContext.Post(delegate { OnWriteLog(new OnWriteLogArgs("Finished calling the rebuild tree view method...")); }, null); } </code></pre> <p>You'll notice at the end of the <code>foreach</code> loop, I do my write that says <code>Finished the compare...</code>, and that DOES write, but the next sync call:</p> <pre><code> syncContext.Post(delegate { OnRebuildTreeView(rArgs); }, null); </code></pre> <p>Never gets executed. Here's that method:</p> <pre><code>private void OnRebuildTreeView(RebuildTreeViewArgs args) { syncContext.Post(delegate { OnWriteLog(new OnWriteLogArgs("Made it to the OnRebuildTreeView method...")); }, null); while (bgw.IsBusy) { syncContext.Post(delegate { OnWriteLog(new OnWriteLogArgs("Sleeping...")); }, null); Thread.Sleep(1000); } syncContext.Post(delegate { OnWriteLog(new OnWriteLogArgs("Starting the rebuild of the TreeView...")); }, null); TreeNode[] tn = args.NewStructure; tvSync.Nodes.Clear(); foreach (TreeNode node in tn) tvSync.Nodes.Add(node); foreach (TreeNode node in tvSync.Nodes) FixCheckedAndUnCheckedNodes(node); ReloadTreeView(args.OnlyShowDifferences); } </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