Silverlight 3 Beta 1 Multi-core programming possibilities using C#

In my previous post “Use lambda expressions in C# to simplify the parallelized code II”, Eduardo Fernandez added a comment asking me whether Silverlight 3 Beta 1 had support for multithreading. I’m adding this post to let you know the possibilities offered by Silverlight 3 Beta 1 to create RIAs that take advantage of multi-core microprocessors.

Disclaimer: I’m talking about a Beta 1 release. Therefore, there is a great possibility to meet differences in the final release. The features provided by Silverlight 3 (final release) could differ from the ones I’m talking about for the Beta 1 release. I’m focusing on C#. However, you can also use Visual Basic and other languages like F# to program Silverlight apps.

You can control the elements defined in XAML using C# 3.0 and a subset of .Net 3.5. Hence, you can use lambda expressions, as explained in my previous post. They are really useful to simplify parallelized code.

You have access to BackgroundWorker (System.ComponentModel.BackgroundWorker). Thus, you can use the BackgroundWorker component to create new threads without the complexity of the Thread class and/or ThreadPool. The BackgroundWorker component gives you instant access to a new thread with a component based scheme. Hence, it is simpler for beginners to start working with it. However, you must be very careful to understand what you’re doing when using it. Running code in additional threads will take advantage of multiple cores.

You have access to the Thread class (System.Threading.Thread) in order to run many concurrent threads with more control capabilities than the ones created using the BackgroundWorker component. The Thread class offers many fine tuning capabilities.

You have access to the ThreadPool class (System.Threading.ThreadPool) in order to work with pools of threads. You can queue work items using the ThreadPool class and you can also use its fine tuning capabilities.

Thus, you have access to these three main elements:
* BackgroundWorker
* Thread class
* ThreadPool class

Everything that you learned working with multithreading and multi-core programming using C# 2.0 and C# 3.0 will be really useful when working with Silverlight 3 Beta 1.

So far, Silverlight 3 Beta 1 will not offer support to Task Parallel Library or the Parallel Extensions. Hence, I guess we’ll have to wait for Silverlight 4. Nevertheless, C# 3.0 and Silverlight 3 Beta 1 will offer great opportunities for developers to tackle the multi-core revolution offering exciting RIAs.

You can find additional information about my thought about the opportunities related to RIA and parallelism reading my post in Go Parallel: http://www.ddj.com/go-parallel/blog/archives/2009/05/designing_rich.html

Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.