代码如下: 定时器设置的enabled=true,interval=1000,运行程序时,代码只执行成功了一次,并且会导致主界面卡。该如何修改
//定时器每秒执行一次
private void timer1_Tick(object sender, EventArgs e)
{
thread1= new Thread(new ThreadStart(zairuthread));
thread1.IsBackground = true;
thread1.Start();
}
private void zairuthread()
{
if (this.InvokeRequired)
{
this.BeginInvoke(new EventHandler(zairu), null);
}
else
{
zairu(this, null);
} }
private void zairu(object sender, EventArgs e)
{
mvideo.GrabImage("D:\\1.jpg");//截图
List<Image> list = new List<Image>();
list = FaceFind.FaceShowzhuye(pictureBox_get.Width, pictureBox_get.Height, "D:\\1.jpg");
int i = list.Count;
switch (i)
{
case 1:
pictureBox_get.Image = list[0];
}
thread1.Abort();
thread1.Join();
}C#多线程定时器
//定时器每秒执行一次
private void timer1_Tick(object sender, EventArgs e)
{
thread1= new Thread(new ThreadStart(zairuthread));
thread1.IsBackground = true;
thread1.Start();
}
private void zairuthread()
{
if (this.InvokeRequired)
{
this.BeginInvoke(new EventHandler(zairu), null);
}
else
{
zairu(this, null);
} }
private void zairu(object sender, EventArgs e)
{
mvideo.GrabImage("D:\\1.jpg");//截图
List<Image> list = new List<Image>();
list = FaceFind.FaceShowzhuye(pictureBox_get.Width, pictureBox_get.Height, "D:\\1.jpg");
int i = list.Count;
switch (i)
{
case 1:
pictureBox_get.Image = list[0];
}
thread1.Abort();
thread1.Join();
}C#多线程定时器
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货