Async Questions with Answers

7 practice questions on Async (C#) with answers and step-by-step solutions. Try 7 samples below, then practise all 7 free in the AptiNest app.

Sample questions

Question 1Easy

Which keyword must a method have before it can use await?

  1. async
  2. task, the return type that carries the result
  3. wait, which pauses a thread until a task ends
  4. yield, which returns items one at a time from an iterator

Answer: A. async

Explanation

await can only be used inside a method marked async. The modifier lets the compiler turn the method into a state machine that can pause.

Step-by-step solution

  1. await pauses the method until the task completes.
  2. Only methods marked async may contain await.
  3. So the method header needs the async keyword.

Why the other options are wrong

  • B. Task is a return type, not the keyword that enables await.
  • C. C# has no wait keyword; the operator is await.
  • D. yield returns items one at a time from an iterator; it does not enable await.

Tip: async opens the door; await is what pauses.

Question 2Medium

Inside an async method, what is printed?

var a = Task.FromResult(2);
var b = Task.FromResult(3);
var r = await Task.WhenAll(a, b);
Console.WriteLine(r[0] + r[1]);
  1. 5
  2. 23
  3. 2
  4. Compile error

Answer: A. 5

Explanation

WhenAll waits for all the tasks and returns their results as an int array in the same order. Adding the two ints gives 5.

Step-by-step solution

  1. WhenAll(a, b) gives an int array with 2 and 3.
  2. r[0] is 2 and r[1] is 3.
  3. 2 + 3 = 5.

Why the other options are wrong

  • B. The values are ints, so + adds them instead of joining the digits.
  • C. Only r[0] would print 2; the code also adds r[1], which is 3.
  • D. WhenAll with two Task<int> values returns an int array, so the code compiles.

Tip: WhenAll returns results in the same order as the tasks you passed in.

Question 3Medium

What does await do inside an async method when the awaited task is not yet complete?

  1. Blocks the current thread until the awaited task finishes
  2. Starts a new thread for the rest of the method
  3. Throws an exception to signal waiting
  4. Frees the thread and resumes later without blocking

Answer: D. Frees the thread and resumes later without blocking

Explanation

At the await point the method is suspended and the thread is freed. When the task completes, the rest continues as a continuation.

Step-by-step solution

  1. Method reaches await.
  2. Task incomplete.
  3. Caller continues; method resumes later.

Why the other options are wrong

  • A. .Result or. Wait() block the thread; await does not.
  • B. await does not create a thread by itself.
  • C. Awaiting an incomplete task is normal and throws nothing.

Question 4Medium

What must the return type be for an async method that returns an int?

  1. int, the plain integer type returned directly from the method
  2. Task, which has no slot to hold the int result
  3. Task<int>
  4. async int, with async written as the return type modifier

Answer: C. Task<int>

Explanation

The async method wraps its int result in a Task<int>. Callers await it to get the int.

Step-by-step solution

  1. The method returns an int value.
  2. Async methods must return Task, Task<T> or void.
  3. So the wrapped result type is Task<int>.

Why the other options are wrong

  • A. An async method must return Task, Task<T> or void, so plain int is not allowed.
  • B. Plain Task has no int result; you need Task<int> to carry the value.
  • D. async is a modifier, not a return type.

Tip: The T in Task<T> is the value you return.

Question 5Medium

Which return type is correct for an async method that returns nothing and can be awaited?

  1. void
  2. Task
  3. Task<void>
  4. async

Answer: B. Task

Explanation

Task represents work with no result value. It lets callers await the method and catch its exceptions.

Step-by-step solution

  1. The method does not return a value.
  2. Plain Task represents the work and its completion.
  3. Callers can await a Task.

Why the other options are wrong

  • A. A void async method cannot be awaited, so callers cannot know when it ends.
  • C. Task<void> is not valid; use plain Task when there is no value.
  • D. async is a modifier, not a type.

Tip: Use Task for async methods with no value; avoid void except for event handlers.

Question 6Hard

In a UI app, a click handler calls .Result on a task. The awaited code needs to resume on the UI thread. Why can this deadlock?

  1. .Result always throws an exception, even when the task succeeds
  2. The compiler rejects every use of .Result in UI code, so the build fails
  3. Result is not thread-safe, so the app corrupts its memory while it waits
  4. The UI thread is blocked, so the awaited code cannot resume

Answer: D. The UI thread is blocked, so the awaited code cannot resume

Explanation

Blocking on. Result holds the UI thread. The awaited continuation needs that same thread to resume, so both wait forever. Using await instead of blocking avoids this.

Step-by-step solution

  1. The UI thread calls. Result and waits.
  2. The awaited work wants to resume on the UI thread.
  3. Neither side can continue, so the app deadlocks.
  4. Use await instead of blocking.

Why the other options are wrong

  • A. .Result returns the value normally when the task completes; the problem is the blocking.
  • B. The code compiles; the problem only shows up at run time.
  • C. The deadlock comes from blocking the thread, not from memory corruption.

Tip: Never block on async code from the UI thread; await it.

Question 7Hard

What is a major problem with async void methods?

  1. The caller cannot await them or catch their exceptions with try/catch
  2. They can only run on the UI thread of a desktop application
  3. They run synchronously and block the caller until finished
  4. They must return an int

Answer: A. The caller cannot await them or catch their exceptions with try/catch

Explanation

With no Task returned, the caller cannot await completion or observe exceptions, which are raised on the synchronization context. Use async Task, except for event handlers.

Step-by-step solution

  1. async void returns nothing to await.
  2. An exception escapes onto the context.
  3. Caller try/catch does not see it.

Why the other options are wrong

  • B. async void methods can run anywhere.
  • C. They are asynchronous like other async methods.
  • D. They return nothing; that is the issue.

Tip: Prefer async Task.

Practise all 7 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all C# topics · All topics