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 for the first time only after the interval time has passed.
Is there a way to raise the Timer.Elapsed
event right after starting the timer ?
I couldn't find any relevant property in the System.Timers.Timer
class.
Task.Run(() => { Timer_Elapsed(null, null); });
After Timer creation/configuration, worked fine for me...
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.
I have implemented in VB.NET with AddHandler
For the first time, the timer will start after 1 second. After that, its interval will be changed to every 30 seconds or whatever...
I just called the
**ElapsedEventHandler**
with null parameters.not sure about
System.Timers.Timer
but tryThis starts immediately (0 milliseconds for first run, 30000 milliseconds for subsequents runs)...
see
http://msdn.microsoft.com/en-us/library/system.threading.timer.aspx
http://msdn.microsoft.com/en-us/library/2x96zfy7.aspx