Deadlock in C# (Interview Guide)

Most developers say:
“Deadlock is when threads block each other.”
That’s correct — but not enough to pass a real interview.

What is a Deadlock?

❌ Bad answer

When threads block each other.

✅ Senior answer

A deadlock occurs when two or more threads are waiting for each other to release resources, causing all of them to be blocked indefinitely. It typically happens due to improper locking or blocking async code.

4 Conditions for Deadlock (important)

👉 All 4 must happen for a deadlock to occur.

Example (classic deadlock)

object lock1 = new object();
object lock2 = new object();

Task.Run(() => {
    lock (lock1) {
        Thread.Sleep(100);
        lock (lock2) { }
    }
});

Task.Run(() => {
    lock (lock2) {
        Thread.Sleep(100);
        lock (lock1) { }
    }
});

Deadlock with async/await (very common)

// ❌ Dangerous
var result = SomeAsync().Result;

👉 Blocking async code like this can cause deadlocks in ASP.NET.

How to avoid deadlocks

Want to practice explaining this like a senior?

Practice Now
← See all .NET interview questions