小白系统定时器使用没有反应,求助
namespace 图形闪烁调试{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
bool picAidThreadMark = true;
System.Timers.Timer timer1 = new System.Timers.Timer();
int picId = 0;
private void pictureBox1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 2000;
while (picAidThreadMark)
{
if (picId == 0)
{
pictureBox1.ImageLocation = @"E:\sleepHelp\图形闪烁调试\图形闪烁调试\bin\Debug\QQ.ico";
}
else pictureBox1.ImageLocation = null;
timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Tick);//到时间的时候执行事件;
}
//pictureBox1.ImageLocation = @"E:\sleepHelp\图形闪烁调试\图形闪烁调试\bin\Debug\QQ.ico";
}
void timer1_Tick(object sender, EventArgs e)
{
this.Invoke(new Action(() =>
{
picId += 1;
picId = picId % 2;
}));
}
}
}
//就是想实现图片闪烁,这段代码怎么会没有反应呢,且线程数一直增加,invoke里每次就整数赋值,赋值完成了这个线程不就应该停止了吗?求助