Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy to split the tasks not running on UI thread to make WPF app more responsive?
    text
    copied!<p>In <a href="http://blogs.msdn.com/b/csharpfaq/archive/2010/06/01/parallel-programming-in-net-framework-4-getting-started.aspx" rel="nofollow">part1 "Getting Started"</a> of </p> <ul> <li>Alexandra Rusina's series. Parallel Programming in .NET Framework 4 </li> </ul> <p>in order to make WPF UI responsive, it is done by outsourcing the intensive computations out of UI. Eventually, the code was changed to: </p> <pre><code>for (int i = 2; i &lt; 20; i++) { var t = Task.Factory.StartNew(() =&gt; { var result = SumRootN(i); this.Dispatcher.BeginInvoke(new Action(() =&gt; textBlock1.Text += "root " + i.ToString() + " " + result.ToString() + Environment.NewLine) ,null); }); } </code></pre> <p>Update: <strong>so shifting the intensive computations out of UI thread.</strong> </p> <p>Here are the quotes from <a href="http://blogs.msdn.com/b/csharpfaq/archive/2010/06/01/parallel-programming-in-net-framework-4-getting-started.aspx" rel="nofollow">Part1 article</a> upon coming to this snippet: </p> <ul> <li><em>"To make the UI responsive, I am going to use tasks, which is a new concept introduced by the Task Parallel Library. A task represents an asynchronous operation that is often run on a separate thread"</em> </li> <li><em>"Compile, run… Well, UI is responsive"</em> </li> </ul> <p>And in order to output to WPF UI from those separate task threads (or to avoid InvalidOperationException that says “The calling thread cannot access this object because a different thread owns it.”) the Dispatcher.BeginInvoke() was engaged. </p> <p>Part2 of the same series <a href="http://blogs.msdn.com/b/csharpfaq/archive/2010/06/18/parallel-programming-task-schedulers-and-synchronization-context.aspx" rel="nofollow">"Parallel Programming: Task Schedulers and Synchronization Context"</a> tells about the same snippet of code (after small change of introducing a local iteration variable): </p> <blockquote> <p>"This one requires more thorough refactoring. I can’t run all the tasks on the UI thread, because they perform long-running operations and this will make my UI freeze. Furthermore, it will cancel all parallelization benefits, because there is only one UI thread.</p> <p>What I can do is to split each task into..."</p> </blockquote> <p>Does not <a href="http://blogs.msdn.com/b/csharpfaq/archive/2010/06/01/parallel-programming-in-net-framework-4-getting-started.aspx" rel="nofollow">the part1-article</a> contradict to <a href="http://blogs.msdn.com/b/csharpfaq/archive/2010/06/18/parallel-programming-task-schedulers-and-synchronization-context.aspx" rel="nofollow">the part2-article</a>? </p> <p>What is the need of splitting the tasks that are not running on UI thread into parts? </p> <p>What do I undermisoverstand here? </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