using System.Runtime.CompilerServices;
using System.Threading.Tasks;
Console.WriteLine("Exception was captured by async state machine");
await new YieldThreadPoolAwaiter();
throw new ApplicationException("Oops!");
public struct YieldThreadPoolAwaiter : INotifyCompletion
public void OnCompleted(Action continuation)
if (continuation == null)
throw new ArgumentNullException(nameof(continuation));
ThreadPool.QueueUserWorkItem(RunAction, continuation);
public void GetResult() { }
private static void RunAction(object state)
public YieldThreadPoolAwaiter GetAwaiter() => this;