Showing results for FAQ - .NET Blog

Oct 15, 2010
Post comments count0
Post likes count0

FAQ :: StartNew() with TaskScheduler.FromCurrentSynchronizationContext() doesn’t work?

Danny Shih
Danny Shih

We’ve seen a number of folks write the following code to execute on the UI thread and get unexpected behavior. TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();Task uiTask = Task.Factory.StartNew(delegate{    // … Update UI component; BUG!}, uiScheduler);The issue is that the StartNew ca...

.NET Parallel Programming
Aug 5, 2010
Post comments count0
Post likes count0

FAQ :: TaskScheduler.UnobservedTaskException event doesn’t work?

Danny Shih
Danny Shih

Recall that if exceptions thrown from Task bodies are left unobserved, they will be escalated.  In .NET 4, this means that TPL will throw them on the finalizer after the Task objects are available for garbage collection.  The UnobservedTaskException event on the TaskScheduler class was added as a last-resort method to observe such excepti...

.NET Parallel Programming
Mar 2, 2010
Post comments count0
Post likes count0

FAQ :: Parallel.ForEach and non-generic collections?

Danny Shih
Danny Shih

.NET 2.0 introduced Generics to allow enhanced code reusability and type safety.  Since then, generic collections (IEnumerable<T>, List<T>, Dictionary<T>, etc.) have become standard and are recommended over their non-generic counterparts (IEnumerable, ArrayList, HashTable, etc.).  As a result, Parallel.ForEach only suppo...

.NET Parallel Programming
Feb 11, 2010
Post comments count0
Post likes count0

FAQ :: Which .NET language is best for parallelism?

Danny Shih
Danny Shih

The new parallelization support in the .NET Framework 4 is implemented purely in libraries and the runtime and does not require special compiler support.  Therefore, it is available to all compliant .NET languages.  This includes all of the managed languages that ship as part of Visual Studio 2010 (Visual C#, Visual Basic, Visual F#, and ...

.NET Parallel Programming
Jan 26, 2010
Post comments count0
Post likes count0

FAQ :: Are all of the new concurrent collections lock-free?

Danny Shih
Danny Shih

(This answer is based on the .NET Framework 4.  As the details below are undocumented implementation details, they may change in future releases.)No.  All of the collections in the new System.Collections.Concurrent namespace employ lock-free techniques to some extent in order to achieve general performance benefits, but traditional locks ...

.NET Parallel Programming
Jan 19, 2010
Post comments count0
Post likes count0

FAQ :: You talk about performance, speedup, and efficiency…what do you mean exactly?

Danny Shih
Danny Shih

All of these terms are overloaded, even in the context of parallel computing.  However, we’ve used them extensively to describe how well our parallel algorithms and demo applications work.  And sometimes, we throw them around carelessly on the blog, forums, etc., so here are our general definitions.Performance is an attribute that r...

.NET Parallel Programming
Jan 11, 2010
Post comments count0
Post likes count0

FAQ :: The Debugger does not correctly handle Task exceptions?

Danny Shih
Danny Shih

The following code correctly observes and handles a Task exception and should print “gotcha!” to the console.  By default though, the Debugger will report a crash.Task t = Task.Factory.StartNew(() => { throw new Exception("poo"); }); try { t.Wait(); } catch (AggregateException) { Console.WriteLine("gotcha!"); } The issue has to ...

.NET Parallel Programming
Jan 5, 2010
Post comments count0
Post likes count0

FAQ :: Why is the speedup not X on my X-way machine?

Danny Shih
Danny Shih

We’ll be regularly posting answers to frequently asked questions that we’ve gotten on the forum, internal email lists, etc.  Here’s the first – enjoy! Why is the speedup not X on my X-way machine?  Or, why does my parallel code run slower?  Less than ideal speedup can typically be attributed to two things: 1.    &...

.NET Parallel Programming