A UI application becomes unresponsive after a button click that calls `GetDataAsync()`. Which of the following best explains the likely cause of the deadlock?

.NET interview question for Advanced practice.

Answer

The UI thread is blocked by .Result waiting for GetDataAsync, but the await inside GetDataAsync needs the UI thread to resume, creating a circular wait.

Explanation

This is a classic 'sync over async' deadlock. The UI thread calls GetDataAsync() and immediately blocks on .Result. Inside GetDataAsync, await captures the UI context and initiates the network request. When the request completes, the await's continuation needs to run on the captured UI thread, but the UI thread is still blocked waiting for .Result to return. This circular dependency causes a deadlock.

Related Questions