在控制台应用程序中,我有以下代码:
private static System.Timers.Timer TaskTimer;
static void Main(string[] args)
{
//run each minute
Func<double> getNextMinute = () => { return (DateTime.Now.RoundUp(TimeSpan.FromMinutes(1)) - DateTime.Now).TotalMilliseconds; };
TaskTimer = new System.Timers.Timer(getNextMinute());
TaskTimer.AutoReset = false;
TaskTimer.Elapsed += (sender, e) =>
{
TaskTimer.Interval = getNextMinute();
TaskTimerCallback();
};
TaskTimer.Start();
bool exit = false;
while (!exit)
{
exit = (command == "exit");
}
}
如果我检查定时器GC生成,它总是为0。
在滴答之前,TaskTimerObject是否有可能收集垃圾?