my program has 3 warnings of the following statement:
This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
What is the warning try to tell me? What should I do?
This is my code: Is it running using multi-threading?
static void Main(string[] args)
{
Task task1 = new Task(Work1);
Task task2 = new Task(Work2);
Task task3 = new Task(Work3);
task1.Start();
task2.Start();
task3.Start();
Console.ReadKey();
}
static async void Work1()
{
Console.WriteLine("10 started");
Thread.Sleep(10000);
Console.WriteLine("10 completed");
}
static async void Work2()
{
Console.WriteLine("3 started");
Thread.Sleep(3000);
Console.WriteLine("3 completed");
}
static async void Work3()
{
Console.WriteLine("5 started");
Thread.Sleep(5000);
Console.WriteLine("5 completed");
}
async
does not mean "multi-threaded". See my intro toasync
post for an explanation of whatasync
does. – Stephen Cleary