*Note: 2.0 is a total re-write of previous releases. There are many breaking changes.
ParallelTasks Threading Library for Windows and Xbox360
A concurrency library optimised for the Xbox360 (Compact Framework), designed to ease the development of applications with scale across n processor cores.
ParallelTasks is designed as a task scheduler to automatically balance work across all available processor cores. The API has been designed to somewhat mimic that of Microsoft's Task Parallel Library, which will ship with Visual Studio 2010. However, that
library is not usable with XNA on the Xbox360. ParallelTasks aims to provide the same core functionality as TPL, but with support across both Windows and Xbox. As such, it will compile on the
, and allocates the bare minimum onto the managed heap
There are various ways to start some concurrent work. All of which are started through the static factory method in the Parallel class. For full documentation and examples, I recommend you read the documentation.
Starting a simple task.
// start a method call on another thread
// DoSomeWork can either be an Action delegate, or an object which implements IWork
Task task = Parallel.Start(DoSomeWork);
// do something else on this thread for a while
// wait for the task to complete. this ensures that after this call returns, the task has finished.
Parallelising a loop.
// sequential loop
for (int i = 0; i < count; i++)
// same loop, but where each iteration may happen in parallel on multiple threads
Parallel.For(0, count, i =>
Start a task which calculates a value and returns it
// Future<T> is similar to a task, but you can retrieve a result from it
Future<double> piFuture= Parallel.Start(CalculatePi);
// do something else for a bit
// retrieve the result. the caller will block until the future has completed. GetResult can only be called once.
double pi = piFuture.GetResult();
Start a long task which would block the thread for a while
// begin loading some file