call Tick event when timer starts
c#, timer
Solution
You can always call your method manually:
private void InitializeTimer()
{
counter = 0;
t.Interval = 750;
t.Enabled = true;
timer1_Tick(null, null);
t.Tick += new EventHandler(timer1_Tick);
}
Problem
I'm using 'System.Windows.Forms.Timer' to repeat a task. But when the timer starts, I have to wait for one interval before the task starts. The interval is set to 10 seconds to give the task enough time to do it's thing. But there is an 'awkward silence' waiting for it to start the first time. Is there a way to trigger the Tick event when the timer is enabled? (I am unable to use threading, callbacks or events to get the task repeat) ``` private int counter; Timer t = new Timer(); private void InitializeTimer() { counter = 0; t.Interval = 750; t.Enabled = true; t.Tick += new EventHandler(timer1_Tick); } private void timer1_Tick(object sender, EventArgs e) { if (counter >= 3) { t.Enabled = false; } else { //do something here counter++; } } ```