2011-12-11 22 views
8

Usando el siguiente código, el temporizador solo se dispara una vez. ¿Qué me estoy perdiendo?System.Threading.Timer solo se dispara una vez

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

Respuesta

20

El temporizador está siendo recopilado por el GC antes de que se dispare nuevamente.
Necesita mantenerlo vivo al guardarlo en un campo.

Cuestiones relacionadas