Skip to content
AtomicReps

Navigation

08/30Computer Science

C# Async.

How a C# program waits: tasks, awaiting, cancellation, and the failures each shape produces.

  • C# Async · 1 of 3

    Tasks

    Which three TaskStatus values mark a finished C# task?

  • C# Async · 2 of 3

    Coordination

    In C#, why does the compiler forbid await inside a lock body?

  • C# Async · 3 of 3

    Deadlocks

    In this C# program, the outer thread has lock a while a task inside lock (b) calls Monitor.TryEnter(a, 200). What does TryEnter return?

    typescript
    var a = new object(); var b = new object();bool tookBoth = false;lock (a){    var other = Task.Run(() => { lock (b) { return Monitor.TryEnter(a, 200); } });    tookBoth = other.Result;}Console.WriteLine($"{tookBoth} done");

Three of the 896 C# Async questions.

Keep going with C# Async, free
Next topic · 09/30C# Collections & LINQ.