Complete the code to start an asynchronous task.
Task.Run(() => [1]);Task.Run expects a delegate or method call. Using DoWork() calls the method synchronously inside the task.
Complete the code to await an asynchronous method.
await [1]();By convention, asynchronous methods end with Async. You await the async method to pause until it completes.
Fix the error in the async method declaration.
public async [1] DoWorkAsync() { await Task.Delay(1000); }
Async methods that do not return a value must return Task, not void or other types.
Fill both blanks to create a dictionary of tasks and await their completion.
var tasks = new Dictionary<string, Task> { {"task1", [1] }, {"task2", [2] } };
await Task.WhenAll(tasks.Values);We store asynchronous method calls returning Task in the dictionary and then await all tasks together.
Fill all three blanks to create an async method that returns a string after delay.
public async Task<string> [1]() { await Task.Delay([2]); return [3]; }
The method name ends with Async, delay is 1000 milliseconds, and it returns the string "Done".