0

I'm trying to create some repro code, which involves a async deadlock like described in here, the only difference being that I'm using a .NET 5 console app (not a ASP.NET app or WinForms app).

What is the minimal reproducible code for a async deadlock on a console app?

Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
Leonardo
  • 10,737
  • 10
  • 62
  • 155
  • Does this help: https://stackoverflow.com/questions/40343572/simulate-async-deadlock-in-a-console-application ? – Lajos Arpad Nov 03 '21 at 15:24
  • A deadlock occurs when two or more threads wait for the same resource, or when they wait on one another to finish work but doing so would require the opposite one to also finish work, leading to both waiting infinitely. This can be simulated using `lock(someShareResource){ methodThatWaitsOnThread2(); } void medthodThatWaitsOnThread2(){ lock(someSharedResource){ ... } }` see above comment for more info – DekuDesu Nov 03 '21 at 15:25
  • 1
    Maybe this helps understand why that specific code doesnt deadlock a console: https://stackoverflow.com/questions/44544053/why-does-this-async-await-code-not-cause-a-deadlock – Jamiec Nov 03 '21 at 15:26
  • @Jamiec your sample does not deadlocks, for me at least... EDIT1, never mind, I misread your comment – Leonardo Nov 03 '21 at 15:37
  • Does this answer your question? [Why does this async/await code NOT cause a deadlock?](https://stackoverflow.com/questions/44544053/why-does-this-async-await-code-not-cause-a-deadlock) – paulsm4 Nov 03 '21 at 16:19
  • You could look at Stephen Cleary's [`Nito.AsyncEx.AsyncContext`](https://github.com/StephenCleary/AsyncEx/wiki/AsyncContext) class. This class can install a synchronization context in a console app, that works similarly with the synchronization context installed automatically in GUI apps. – Theodor Zoulias Nov 03 '21 at 16:20

0 Answers0