Async / await interview questions
Tasks, continuations, synchronization context, cancellation.
4 questions with answers and explanations · 2 flashcards
Key ideas
awaiton an incomplete task returns to the caller and schedules the rest of the method as a continuation. No thread is blocked while waiting.- Code before the first
awaitruns synchronously on the caller's thread. - Avoid
.Result/.Wait()(deadlocks, thread-pool starvation). Go async all the way and passCancellationTokens. async voidis only for event handlers.
Questions
- What happens when execution reaches await on a task that hasn't completed yet?Multiple choiceEasy
- In what order are the letters printed? (Each WriteLine prints one letter per line.)What does this code output?Hard
- Which async practices are recommended? Select all that apply.Select all that applyMedium
- A desktop app freezes forever when a button handler calls GetDataAsync().Result. Explain why this deadlocks and how to fix it.Interview answerHard