Consider the following code
class Program
{
static void Continue()
{
Console.Out.WriteLine("Continue t1");
}
static async Task AsyncStart()
{
Console.Out.WriteLine("AsyncStart");
return;
}
static void Main(string[] args)
{
Task t3 = AsyncStart().ContinueWith((ant) => { Continue(); });
Console.Out.WriteLine("BEFORE");
Task.WhenAny(new Task[] { t3 });
Console.Out.WriteLine("AFTER");
}
}
The output is
AsyncStart
BEFORE
AFTER
Press any key to continue . . .
Continuation is not running!!!!
Yes, I understand the AsyncStart does not contain any await (CS1998), but I still expect t3 to run the continuation. I am missing something very basic
Your process ended before the continuation (which runs on a background thread) had the chance to run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With