System.Threading.Timer只触发一次

ebb*_*ebb 8 c# multithreading

使用下面的代码,计时器只会触发一次.我错过了什么?

public static List<string> Test = new List<string> { "TEST1", "TEST2" };

public static void Start()
{
    var t = new System.Threading.Timer(o =>
    {
        foreach (var item in Test)
        {
            Console.WriteLine("Say hello!"); 
        }
    }, null, 0, 1250);
}
Run Code Online (Sandbox Code Playgroud)

SLa*_*aks 21

GC会在再次触发之前收集计时器.
你需要将它存储在一个字段中以保持活着.