I am trying to use Task.WhenAll to wait for several tasks to complete.
My code is below - it is supposed to run several async tasks, each of which extracts the bus route, and then adds them to the local array. However, Task.WhenAll (...) returns immediately, and the number of arrays of local routes is zero. This seems strange, since I would expect that the various statements βwaitβ in each task mean that the thread is paused and the task will not return until it is finished.
List<Task> monitoredTasks = new List<Task>(); foreach (BusRouteIdentifier bri in stop.services) { BusRouteRequest req = new BusRouteRequest(bri.id); // Start a new task to fetch the route for each stop Task getRouteTask = Task.Factory.StartNew(async () => { var route = await BusDataProviderManager.DataProvider.DataBroker.getRoute(req);
I'm obviously doing something wrong, but what?
source share