Click here to Skip to main content
15,039,149 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to call all async all once in parallel method ?
C#
 public static async Task resendAll()
        {
// how to call the below two function in parallel async method ?
        }
public static async Task rePostRoomReservation( )
{

}
public static async Task rePostHallReservation()
{

}


What I have tried:

C#
List<string> functionName = List<string>();
functionName.add("rePostRoomReservation");
functionName.add("rePostHallReservation");
foreach (string name in functionName )
{
}
await Task.WhenAll ()
Posted
Updated 27-Jun-21 22:40pm
Comments
Kenneth Haugland 26-Jun-21 9:32am
   
Ill take that back, you just need some new Task items, and start them in succession
Member 14921707 26-Jun-21 10:44am
   
show me in code, please
Gerry Schmitz 26-Jun-21 12:38pm
   
You have to different functions; 2 async calls. Trying to apply a generic parallel pattern in this case is mostly pointless.
Member 14921707 27-Jun-21 1:37am
   
instead of calling all method one by one like
Copy Code
 
await rePostRoomReservation();
 await rePostHallReservation();

There is method for Execution parallel not one by one, for fast execution.

1 solution

Simple - don't await the tasks as you create them; store them, and await the result of a Task.WhenAll call instead:
C#
Task roomReservationTask = rePostRoomReservation();
Task hallReservationTask = rePostHallReservation();
await Task.WhenAll(roomReservationTask, hallReservationTask);
Task.WhenAll Method (System.Threading.Tasks) | Microsoft Docs[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900