I’m working with the patterns & practices team on a Metro style app with C++ and XAML called Hilo. Hilo is a basic photo viewing and tagging app that totally re-imagines Hilo for Windows 7 by embracing new form factors and experiences that Windows 8 enables.
One of the more exciting aspects of Hilo is the use of the new PPL tasks to enable a fast and fluid user experience. The heart of PPL tasks, the concurrency::task class, simplifies the process of performing operations asynchronously, or in the background, and then using the results of the asynchronous operations to update the UI.
For example, Hilo defines the ThumbnailGenerator class to generate thumbnails for pictures that are displayed on the app’s Start menu tile. The ThumbnailGenerator::Generate queues a task that converts each image in the provided vector to a thumbnail that is displayed on the tile. The call to concurrency::when_all enables this method to collect the results when they are ready and produce a second vector that contains the resulting thumbnail images.
This method behaves asynchronously. The caller to this method receives a task object and can then chain additional tasks that will run after that task completes.
Here’s another example. This one creates a chain of continuations to save the thumbnail image to disk. The ThumbnailGenerator::InternalSaveToFile method is called by ThumbnailGenerator::CreateLocalThumbnailAsync in the previous example.
Although this method is called as part of another asynchronous operation, we got in the habit of always using asynchronous operations so that we can later compose them together. This is key to keeping work off of the UI thread, and thus keeping the app responsive to user input.
We also strive to use lambda functions, standard algorithms, the auto keyword, and other modern C++ constructs as much as possible.
Check out Hilo for Windows 8 at http://hilo.codeplex.com. You’ll need Windows 8 Consumer Preview and Microsoft Visual Studio 11 Express Beta for Windows 8 to run the sample.
This project is a work in progress. Try it today and be sure to join us on the Discussions tab. We’d love to hear your feedback on our progress!