When an async
method that is awaited upon throws an exception, the exception is stored somewhere and throwing it is delayed. In a WinForms or WPF application, it uses SynchronizationContext.Current
to post throwing of the exception. However, in e.g. a console application, it throws the exception on a thread pool and it brings down the application.
How can I prevent exceptions thrown from an async
method from bringing down the application?
EDIT:
Appearantly the issue I'm describing is because I have void
async
methods. See comments.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…