I have a console app and I want to launch tasks one after the other.
Here is my code:
static void Main()
{
string keywords = "Driving Schools,wedding services";
List<string> kwl = keywords.Split(',').ToList();
foreach(var kw in kwl)
{
Output("SEARCHING FOR: " + kw);
Task t = new Task(() => Search(kw));
t.Start();
t.Wait();
}
Console.ReadLine();
}
static async void Search(string keyword)
{
// code for searching
}
The problem is that it doesn't wait for the first task to finish executing. It fires off the subsequent tasks concurrently.
I am working with a rate limited API so I want to do one after the other.
Why is it not waiting for one search to finish before starting the next search?