为什么System.Timers.Timer在GC中幸存,但在System.Threading.Timer中却不行?
看来System.Timers.Timer实例是通过某种机制保持活动的,但System.Threading.Timer实例却没有。 带有定期System.Threading.Timer和自动重置的示例程序System.Timers.Timer: class Program { static void Main(string[] args) { var timer1 = new System.Threading.Timer( _ => Console.WriteLine("Stayin alive (1)..."), null, 0, 400); var timer2 = new System.Timers.Timer { Interval = 400, AutoReset = true }; timer2.Elapsed += (_, __) => Console.WriteLine("Stayin alive (2)..."); timer2.Enabled = true; System.Threading.Thread.Sleep(2000); Console.WriteLine("Invoking GC.Collect..."); …