Can I tie an anonymous function to a Timer's tick event?

前端 未结 3 1964
渐次进展
渐次进展 2021-02-07 16:09

If a Tick-handling function will only be used in one context (i.e. always in the same function in combination with the same Timer object), why bother make it a separate function

3条回答
  •  遇见更好的自我
    2021-02-07 16:37

    A complete example would be:

        Timer timer = new Timer();
        timer.Interval = 500;
        timer.Tick += (t, args) =>
            {
                timer.Enabled = false;
                /* some code */
            };
        timer.Enabled = true;
    

提交回复
热议问题