How to fire timer.Elapsed event immediately

前端 未结 10 1188
独厮守ぢ
独厮守ぢ 2020-12-10 00:17

I\'m using the System.Timers.Timer class to create a timer with an Timer.Elapsed event. The thing is the Timer.Elapsed event is fired

10条回答
  •  自闭症患者
    2020-12-10 01:10

    Here is the easy answer. (Assuming you're using a Windows form)

    After dragging your timer control to your form, set the enabled property to true, and the Interval property to whatever you want the initial value to be. (100 is the default and will start the tick event immediately)

    Then within your tick event, simply check the value of the Interval property. If it is not your desired value, set it. It's that simple. The same can be accomplished in your C# code if creating a timer on the fly.

提交回复
热议问题