Hi @Winanjaya Amijoyo,
You should change your code like below.
// 1st Process
if (providerId == "1")
{
await Providers.Provider1.Do_ProcessAsync(token, param1, param2);
}
// 2nd Process
await Do_Other_Process1Async(x, y, z);
await Do_Other_Process2Async(x, y, z);
await Do_FinalAsync(x, y, z);
Here is my test code and test result, you also can test in your side.
namespace ConsoleApp1
{
internal class Program
{
static async Task Main(string[] args)
{
string providerId = "1";
string token = "exampleToken";
int param1 = 10, param2 = 20;
int x = 1, y = 2, z = 3;
// Simulate the first process
if (providerId == "1")
{
Console.WriteLine("Start the first process...");
await Do_ProcessAsync(token, param1, param2);
Console.WriteLine("First process completed");
}
// Simulate the second process
Console.WriteLine("Start the second process...");
await Do_Other_Process1Async(x, y, z);
await Do_Other_Process2Async(x, y, z);
await Do_FinalAsync(x, y, z);
Console.WriteLine("Second process completed");
}
static async Task Do_ProcessAsync(string token, int param1, int param2)
{
// Simulate asynchronous processing using Task.Delay
await Task.Delay(3000); // Assuming processing takes 3 seconds
Console.WriteLine("Do_ProcessAsync completed");
}
static async Task Do_Other_Process1Async(int x, int y, int z)
{
await Task.Delay(2000); // Assuming processing takes 2 seconds
Console.WriteLine("Do_Other_Process1Async completed");
}
static async Task Do_Other_Process2Async(int x, int y, int z)
{
await Task.Delay(1000); // Assuming processing takes 1 second
Console.WriteLine("Do_Other_Process2Async completed");
}
static async Task Do_FinalAsync(int x, int y, int z)
{
await Task.Delay(500); // Assuming processing takes 0.5 seconds
Console.WriteLine("Do_FinalAsync completed");
}
}
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Jason