Skip to content
Sharp

Async / await interview questions

Tasks, continuations, synchronization context, cancellation.

4 questions with answers and explanations · 2 flashcards

Key ideas

  • await on 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 await runs synchronously on the caller's thread.
  • Avoid .Result/.Wait() (deadlocks, thread-pool starvation). Go async all the way and pass CancellationTokens.
  • async void is only for event handlers.

Questions

  1. What happens when execution reaches await on a task that hasn't completed yet?Multiple choiceEasy
  2. In what order are the letters printed? (Each WriteLine prints one letter per line.)What does this code output?Hard
  3. Which async practices are recommended? Select all that apply.Select all that applyMedium
  4. A desktop app freezes forever when a button handler calls GetDataAsync().Result. Explain why this deadlocks and how to fix it.Interview answerHard