Hi
When using System.Threading.Timer, and initializing a windows form on the timer's tick event, the form becomes unresponsive. Why is that, and how can I avoid it?
This simple sample code shows the problem; the two first windows ("Original" and "Manual") works fine, but "Timer" becomes unresponsive at once.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1.Forms
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
this.Text = "Original";
this.Left = 0;
Form f = new Form();
f.Text = "Manual";
f.Show();
f.Left = this.Width;
TimerCallback tCallback = new TimerCallback(Timer_Tick);
System.Threading.Timer timer = new System.Threading.Timer(tCallback, null, 1000, System.Threading.Timeout.Infinite);
}
void Timer_Tick(object o)
{
Form f = new Form();
f.Text = "Timer";
f.Show();
f.Left = this.Width * 2;
}
}
}