hi friends,
I am looping insert method but for loop is not working properly,it is coming out from the loop continuously not executing.
if(date==dbdate)
{
Insert(fromdate,date,token);
}else
{
for((int i=1;i<=4;i++)
{ fromdate=date.AddDays(i).ToString("yyyy-MM-dd");
Insert(fromdate,date,token);
} }
Public async void Insert((string fromdate,DateTime dt,string token){
}
Please tell me how to do this one?

Amit MohantyRank #112 · 20K reputationPosted Oct 26, 2022, 1:20 AM EDT
Try this
if (date == dbdate) { await Insert(fromdate, date, token); } else { var tasks = new List(); for (int i = 1; i <= 4; i++) { fromdate = date.AddDays(i).ToString("yyyy-MM-dd"); tasks.Add(Insert(fromdate, date, token)); } await Task.WhenAll(tasks); } public async Task Insert(string fromdate, DateTime dt, string token) { // your code to insert records await Task.Delay(1000); }