You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to use AsyncContext to replace System.Windows.Threading.Dispatcher but ran into a problem: after an exception was thrown, the program would wait forever instead of exiting. It seems to be because the background async void loops were now allowed to continue running indefinitely even while the main thread body was terminated.
It seems strange that a program should continue running after an exception, so this seems to be a bug or undesirable default behavior. (The reverse situation where an async void function throws an exception seems to work correctly.)
Here is a reproduction of the problem:
// Dependencies: .NET 7, Nito.AsyncEx.Context 5.1.2using Nito.AsyncEx;namespace TestNet7;internalclassProgram{staticintMain(string[]args)=> AsyncContext.Run(()=> AsyncMain(args));staticasyncTask<int>AsyncMain(string[]args){_=args;//throw new Exception("A");
Console.WriteLine("A");await Task.Delay(TimeSpan.FromMilliseconds(1));//throw new Exception("B");
Console.WriteLine("B");
ScheduleC();thrownew Exception("D");// Expected: Program immediately crashes.// Actual: Program waits 1 second to crash.return0;}staticasyncvoidScheduleC(){//for (;;) // With this, the program can never crash!{await Task.Delay(TimeSpan.FromSeconds(1));//throw new Exception("C");
Console.WriteLine("C");}}}
Thank you.
The text was updated successfully, but these errors were encountered:
Hello,
I was trying to use
AsyncContext
to replaceSystem.Windows.Threading.Dispatcher
but ran into a problem: after an exception was thrown, the program would wait forever instead of exiting. It seems to be because the backgroundasync void
loops were now allowed to continue running indefinitely even while the main thread body was terminated.It seems strange that a program should continue running after an exception, so this seems to be a bug or undesirable default behavior. (The reverse situation where an
async void
function throws an exception seems to work correctly.)Here is a reproduction of the problem:
Thank you.
The text was updated successfully, but these errors were encountered: