Challenge - 5 Problems
Async Execution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of async method with Task.Delay
What is the output of this C# program when run?
C Sharp (C#)
using System; using System.Threading.Tasks; class Program { static async Task Main() { Console.WriteLine("Start"); await Task.Delay(100); Console.WriteLine("End"); } }
Attempts:
2 left
💡 Hint
Remember that await pauses the method until the delay finishes.
✗ Incorrect
The program prints "Start" first, then awaits Task.Delay(100), which pauses asynchronously, then prints "End" after the delay.
❓ Predict Output
intermediate2:00remaining
Order of execution with async void
What will be printed when this program runs?
C Sharp (C#)
using System; using System.Threading.Tasks; class Program { static async void PrintAsync() { Console.WriteLine("Before delay"); await Task.Delay(50); Console.WriteLine("After delay"); } static void Main() { PrintAsync(); Console.WriteLine("Main finished"); Task.Delay(100).Wait(); } }
Attempts:
2 left
💡 Hint
async void methods start running synchronously until the first await.
✗ Incorrect
PrintAsync prints "Before delay" synchronously, then awaits Task.Delay(50). Meanwhile, Main prints "Main finished" and waits 100ms to keep the program alive. After delay, "After delay" is printed.
🔧 Debug
advanced3:00remaining
Identify the cause of deadlock in async code
This code causes a deadlock when run. What is the reason?
C Sharp (C#)
using System; using System.Threading.Tasks; class Program { static void Main() { var result = GetData().Result; Console.WriteLine(result); } static async Task<string> GetData() { await Task.Delay(100); return "Done"; } }
Attempts:
2 left
💡 Hint
Think about how .Result blocks the main thread and how async continuations work.
✗ Incorrect
Calling .Result blocks the main thread waiting for the async method to complete. The async method tries to resume on the same thread (captured context), but that thread is blocked, causing a deadlock.
❓ Predict Output
advanced2:00remaining
Output of async method with ConfigureAwait(false)
What will this program print?
C Sharp (C#)
using System; using System.Threading.Tasks; class Program { static async Task Main() { Console.WriteLine("Start"); await PrintMessageAsync(); Console.WriteLine("End"); } static async Task PrintMessageAsync() { await Task.Delay(50).ConfigureAwait(false); Console.WriteLine("Inside async method"); } }
Attempts:
2 left
💡 Hint
ConfigureAwait(false) affects context capture but does not change the order of awaited code.
✗ Incorrect
The method prints "Start", then awaits PrintMessageAsync. Inside PrintMessageAsync, after the delay, it prints "Inside async method". Then Main prints "End". The order is preserved.
🧠 Conceptual
expert3:00remaining
Understanding async execution and thread usage
Which statement best describes how async/await affects thread usage in C#?
Attempts:
2 left
💡 Hint
Think about what happens to the thread when an await is hit.
✗ Incorrect
When an await is reached, the current thread is freed to do other work. The continuation resumes later on a thread from the thread pool or the original synchronization context if captured.