繁体   English   中英

System.Threading.Timer只触发一次

[英]System.Threading.Timer only fires once

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

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);
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM