Recall & Review
beginner
What is a
Task in C#?A
Task represents an asynchronous operation that does not return a value. It lets your program do work in the background without blocking the main thread.Click to reveal answer
beginner
What is the difference between
Task and Task<T>?Task is for async operations that return no result. Task<T> is for async operations that return a value of type T when completed.Click to reveal answer
beginner
How do you get the result from a
Task<T>?You can use the
await keyword to wait for the task to finish and get its result, like: T result = await task;Click to reveal answer
intermediate
What happens if you call
Wait() on a Task?Calling
Wait() blocks the current thread until the task finishes. This can cause your program to freeze if used on the main thread.Click to reveal answer
intermediate
Why is using
async and await better than blocking with Wait()?Because <code>async</code> and <code>await</code> let your program continue running other work while waiting, improving responsiveness and avoiding freezes.Click to reveal answer
Which type should you use for an async method that returns a number?
✗ Incorrect
Use
Task<int> to represent an async operation that returns an integer.What does
await do when used with a Task?✗ Incorrect
await pauses the method but lets other work run on the thread.What is the return type of an async method that does not return a value?
✗ Incorrect
Async methods that don't return a value should return
Task.Which of these can cause your UI to freeze?
✗ Incorrect
Calling
Wait() blocks the thread and can freeze the UI.How do you declare an async method that returns a string?
✗ Incorrect
Use
async Task<string> to return a string asynchronously.Explain the difference between
Task and Task<T> and when to use each.Think about whether your async method returns a value or not.
You got /4 concepts.
Describe how
await works with Task and why it is preferred over blocking calls.Consider what happens to the program flow when you await a task.
You got /4 concepts.