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.
Community comments
It may be MIT X11 licenced
by 陈 国辉,
Re: It may be MIT X11 licenced
by Jonathan Allen,
F# Async Monad and Agents/Actors can be used in Silverlight Today
by Faisal Waris,
Existing solutions from Microsoft today
by Stefan Dobrev,
It may be MIT X11 licenced
by 陈 国辉,
Your message is awaiting moderation. Thank you for participating in the discussion.
Task Parallel Library for Silverlight is licensed under the same licenses as the rest of the Mono framework. What is mono framework?
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
by Jonathan Allen,
Your message is awaiting moderation. Thank you for participating in the discussion.
How very embarrassing. You are correct, the class libraries are released under MIT X11.
mono-project.com/FAQ:_Licensing
F# Async Monad and Agents/Actors can be used in Silverlight Today
by Faisal Waris,
Your message is awaiting moderation. Thank you for participating in the discussion.
Silverlight requirements are more for concurrency and IO parallelism rather than task parallelism.
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
by Stefan Dobrev,
Your message is awaiting moderation. Thank you for participating in the discussion.
There are a couple of existing "solutions" that comes from Microsoft:
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.
-sdobrev