Channels ▼

Gastón Hillar

Dr. Dobb's Bloggers

Windows Phone 7 Series Multicore Programming Features

August 24, 2010

The application development platform for Windows Phone 7 Series is Silverlight. Silverlight for Windows Phone supports core Silverlight features, including the .NET threading model. Windows Phones Games based on XNA Framework also support the .NET threading model. Therefore, if you develop applications that target a Windows Phone 7 Series device with a dual-core microprocessor, you can work with multithreaded code to take advantage of the two cores.

Mobile devices such as smartphones and MIDs (short for "Mobile Internet Devices") are adding more processing power. Some manufacturers are already using multicore microprocesors in these devices. Rumors indicate that some Windows Phone 7 Series devices might be part of the new generation of multicore mobile devices. The minimum hardware requirements for Windows Phone 7 Series devices specify a single-core microprocessor but it seems there are plans for smartphones powered by a dual-core microprocessor.

A few months ago, I attended some excellent sessions related to the next generation of multicore mobile devices at Multicore Expo 2010. I realized that leveraging the power of multicore smartphones was going to be the next big challenge for mobile application developers. However, if you already have experience in translating multicore power into application performance, you will be able to take advantage of this experience with the next generation of multicore mobile devices.

How can you take advantage of a dual-core microprocessor in a Windows Phone 7 Series device? If you develop a Silverlight for Windows Phone application, you can take advantage of multiple cores by creating threads. Silverlight for Windows Phone provides you access to the old .NET multi-threading model with similar features than the ones provided by Silverlight 4. You can access the System.Threading namespace, create threads, work with the thread pool, synchronize multiple threads, use atomic operations and even use the System.ComponentModel.BackgroundWorker component. The following C# code snippet of a Silverlight for Windows Phone Application shows a simple example of a Click event handler for a Button control that does some work in a new thread, thread1, and then updates the UI thread indicating that the work has been done.

// This code requires
// using System.Threading
private void button1_Click(object sender, RoutedEventArgs e)
{
    var thread1 = new Thread(() =>
        {
            // Do some work
            // The code runs in the new independent thread
            // The code that does some work
            // should be added here
            // End of Do some work
            Dispatcher.BeginInvoke(() =>
                {
                    // Update the UI thread
                    button1.Content = "Work done!";
                });
        });
    // Start the asynchronous execution of thread1
    // The UI thread remains responsive while thread1 runs
    thread1.Start();
}

However, remember that the creation of a new System.Threading.Thread instance represents the creation of a new managed thread and it is an expensive operation. You should also consider the usage of the System.Threading.ThreadPool class to run background work.

Silverlight for Windows Phone doesn't provide access to the new parallel programming features added in .NET Framework 4. The same happens in Silverlight 4, you don't have access to TPL (short for "Task Parallel Library"), PLINQ or the new coordination data structures. You have to work with the old .NET threading model. However, if you work with the appropriate Visual Studio 2010 edition to develop Silverlight for Windows Phone applications, you can take advantage of the new debugging features. For example, the new Parallel Stacks window is really helpful to debug complex code when you work with multiple threads. You can use this new window to debug multi-threaded Silverlight for Windows Phone applications.

The Microsoft.Phone.Tasks namespace provides classes that let you run tasks related to the phone. For example, the Microsoft.Phone.Tasks.WebBrowserTask class allows you to launch the Web browser application from your application. Microsoft.Phone.Tasks doesn't provide access to the creation of tasks assigned to threads. It isn't an equivalent of the System.Threading.Tasks namespace introduced in .NET Framework 4 and also known as TPL. You cannot create tasks to take advantage of multicore, you have to work with threads.

If you develop a Windows Phone Game, you can also take advantage of multiple cores by creating threads or taking advantage of the ThreadPool class. You can use old .NET multi-threading model in your code that works with XNA Framework for Windows Phone.

If you work with Silverlight 4 and you work with multi-threaded code, you will be able to use this experience to take advantage of Windows Phone 7 Series devices with a dual-core microprocessor. You just have to wait for the new multicore smartphones to hit the market. If rumors are true, you will want to add threads to your new smartphone applications or games to put the additional core to work.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video