Created
August 21, 2024 16:15
-
-
Save pavelsavara/8bdd069170a1230b85bbdc54e1f6fca0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Prog | |
{ | |
static void TimerHandler(object _) | |
{ | |
Console.WriteLine("TimerHandler A"); | |
} | |
static void SetNextTimer() | |
{ | |
Console.WriteLine("SetNextTimer A"); | |
var task = Task.Delay(100); | |
// note that the continuation is not awaited and nothing is keeping the Task alive from GC | |
task.ContinueWith(TimerHandler, TaskScheduler.Default); | |
} | |
public static async Task<int> Main(string[] args) | |
{ | |
Console.WriteLine("Main A"); | |
SetNextTimer(); | |
Console.WriteLine("Main B"); | |
GC.Collect(); | |
GC.WaitForPendingFinalizers(); | |
Console.WriteLine("Main C"); | |
await Task.Delay(200); | |
GC.Collect(); | |
GC.WaitForPendingFinalizers(); | |
await Task.Delay(200); | |
GC.Collect(); | |
GC.WaitForPendingFinalizers(); | |
Console.WriteLine("Main D"); | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment