System.Windows.Forms.Timer doesn't tick when fired by System.Timers.Timer's event

  • Thread starter Thread starter Jeff0803
  • Start date Start date
J

Jeff0803

Guest
My program have two different timer.

The one is System.Windows.Forms.Timer(tf) and another is System.Timers.Timer(tt).

tf is ticked normally when started from Form_Load.

However it is not fired when ticked from tt.

I need to use two different type of timers.

How to solve this issue?

I made sample program below.

public partial class Form1 : Form
{
System.Timers.Timer tt;
System.Windows.Forms.Timer tf;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
tt = new System.Timers.Timer();
tt.AutoReset = false;
tt.Interval = 5000;
tt.Elapsed += OnTimedEvent;
tt.AutoReset = false;
tt.Enabled = true;
tt.Start();
}
private void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
tf = new System.Windows.Forms.Timer();
tf.Tick += new EventHandler(TimerEventProcessor);

// Sets the timer interval to 5 seconds.
tf.Interval = 5000;
tf.Start();
}
private void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
{
tf.Stop();
MessageBox.Show("TimerEventProcessor was invoked!");
}
}

Continue reading...
 
Back
Top