Skip to content Skip to sidebar Skip to footer

Starting Multiple Async Tasks And Process Them As They Complete (c#)

So I am trying to learn how to write asynchronous methods and have been banging my head to get asynchronous calls to work. What always seems to happen is the code hangs on 'await'

Solution 1:

In short when you combine async with any 'regular' task functions you get a deadlock

http://olitee.com/2015/01/c-async-await-common-deadlock-scenario/

the solution is by using configureawait

var html = await client.GetStringAsync(_link).ConfigureAwait(false);

The reason you need this is because you didn't await your orginal thread.

// ***Create a query that, when executed, returns a collection of tasks.
IEnumerable<Task<string[]>> downloadTasksQuery = from task in taskList selectQueryHtml(loadScreen,links[task], symbols[task]);

What's happeneing here is that you mix the await paradigm with thre regular task handling paradigm. and those don't mix (or rather you have to use the ConfigureAwait(false) for this to work.

Post a Comment for "Starting Multiple Async Tasks And Process Them As They Complete (c#)"