System.Threading.Timer only fires once

Using the code below, the timer only fires once. What am I missing?

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); } 
+8
multithreading c #
source share
1 answer

The timer is going to the GC before it fires again.
You need to save it in memory by storing it in the field.

+20
source share

All Articles