I would like to execute async operations in parallel, in Silverlight 5, with limited concurency.
My code is like :
public async void btn_click(object s, RoutedEventArgs e)
{
await DoAllWork();
}
private async Task DoAllWork()
{
//Get work to do
int[] wrk = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
//Start the tasks
Task[] tasks = new Task[wrk.Length];
for (int i = 0; i < wrk.Length; i++)
{
int item = wrk[i];
tasks[i] = WorkSingleItem(item);
}
await TaskEx.WhenAll(tasks);
}
private async Task WorkSingleItem(int item)
{
//a very long operation
var response = await Request(item);
await Handle(response);
}
I have found this article : http://msdn.microsoft.com/en-us/library/ee789351(v=vs.110).aspx
How can I await my work method, that start all my long operations with the "limited concurrency scheduler", and with each item work not relying on synchronization context to avoid code executed in UI thread...