Task Parallel Library for Silverlight
Silverlight’s asynchronous service model forces developers to deal with multi-threading from the very beginning. So it seems odd that Microsoft choose to omit the Task Parallel Library, which is the core of .NET’s multi-threading infrastructure. Fortunately there are options.
If the LGPL 2.0 license isn’t an issue for you, you can use a port of the Mono implementation. Robert McLaws and Jrmie "Garuma" Laval have done just this, and published their work on NuGet under the title Task Parallel Library for Silverlight - 2.0. Unfortunately they haven’t published a copy of the LGPL license, the source code, or the Mono copyright notifications. While this can be corrected, it does pose some legal problems in the meantime.
Working under the assumption that they will fix this oversight, here’s what you get in their package:
- An implementation for both Silverlight 3 and 4
- An implementation for Silverlight for Windows Phone 7 and 7.1
- The Task Parallel Library itself (System.Treading.Tasks)
- The Coordination Data Structures (System.Collections.Concurrent)
- The cancellation infrastructure (i.e. CancellationToken)
- Parallel for loops, but not parallel LINQ expressions
Another option is the PortableTPL by David Catuhe. This isn’t the real TPL, but rather a simplification originally designed to be educational. That said, it does run on Silverlight, Windows Phone 7, and XBox 360 and is available under the liberal Microsoft Public License. It has the core TPL features suchs as Tasks and cancellation, but lacks the Coordination Data Structures.
It may be MIT X11 licenced
If mono framework = runtime libraries -> LGPL 2.0;
If mono framework = class libraries -> MIT X11.
I think TPL use MIT X11.
Re: It may be MIT X11 licenced
F# Async Monad and Agents/Actors can be used in Silverlight Today
Sequencing async computations are a significant need.
F# handles these quite well using functional paradigms.
Learning F# / functional programming is an investment, no doubt, but its well worth the effort.
Existing solutions from Microsoft today
- Use AsyncCtpLibrary_Silverlight.dll that comes with Visual Studio Async CTP.
- Use Silverlight 5.
However if you want to use the concurrent collections you will have to resort to bundling Mono's implementation. Maybe in the final version of Silverlight 5 they will include some of them, but nothing has been said publicaly.
Srini Penchikala Aug 21, 2014