c# - Await things but make things run in concurrent manner -


I am creating an Android app, but this question is mostly related to C #.
In my code I need to have some things, some of them do not need other parts and in the manner of equality some of them should wait for the last action to get results. I am doing everything I can do in an async way. It seems that I am always waiting to finish things before the next action.

Here's an example that I'm trying to do:

  1. Bring the user's image to the phone.
  2. Get a list of recent phone calls.
  3. Get a list of specific contacts from the phone.
  4. Get the data about number # 2 and # 3 from the server.

Item # 1 is not related to something else I need to be concurrent with others They do not need to wait for returns when it ends , Then he should update the UI.

Items # 2 & amp; # 3 should be in concurrent When they end both , they should update the UI

The item # 4 can only happen when # 2 and # 3 finished Will happen.

My question is, what do I need to get this kind of requirement I only ask for directions.

Parallel is used for CPU intensive performance using most threads. My guess is that you actually mean concurrent , which means that asynchronous action is not simultaneously and sequentially .

How to do this is a simple layout async methods should be used with the task. When all which meet many tasks to complete asynchronous Enables:

  async Task Fu () {var t1 = first (); Var t2 = Second and third and Foth (); Awaiting work When all (T1, T2); } Async Task First () {// Bring the user image from the phone. // update UI} async Task II and third and fourth () {var t2 = second (); Var t3 = third (); Awaiting work When all (T2, T3); // Wait fourth (updated) of UI; }  

If you mean parallel execution, you will have to offload the job by using ThreadPool thread, task.run But this will only parallel the synchronous parts of asynchronous methods.


There is no real reason to store these tasks in the variable, it is only for clarity, in fact I will write the wait job. When all (second () Third ()) (with proper names)


Comments