||
给你个提示: 你的两个线程同时访问了同一幅图像。 造成冲。简单的方法是在每个线程都要拥有自己的一份图像副本。分别对自己的副本进行对写操作。
你的这个问题可能不是因为没用队列造成的,但你肯定是要用队列。你发送的速度远远跟不上捕获的速度的。
private void thDrawRectangleToShowError()
{
g = this.pictureBox1.CreateGraphics();
userSetPen = new Pen(clrUserSetResultColor, 3);
grayPen = new Pen(Color., 3);
int i3 = 1;
while (true)
{
//s++;
//Invoke(new MethodInvoker(delegate
// {
// label3.ForeColor = Color.Red;
// label3.Text = " 等待检测... ";
// }));
//if(g!=null)
// g.Dispose();
//try
//{
// //g = this.pictureBox1.CreateGraphics();
//}catch(Exception ex)
//{
// MessageBox.Show(ex.Message);
//}
for (int i = 0; i < errorCount; i++)
{
index = arrErrorFuseLocation[i];
g.DrawRectangle(userSetPen,
new Rectangle(arrFeature[index].x0, arrFeature[index].y0,
arrFeature[index].x1 - arrFeature[index].x0,
arrFeature[index].y1 - arrFeature[index].y0));
//g.DrawRectangle(userSetPen,
// new Rectangle(33,33,33,33));
Thread.Sleep(300);
g.DrawRectangle(grayPen,
new Rectangle(arrFeature[index].x0, arrFeature[index].y0,
arrFeature[index].x1 - arrFeature[index].x0,
arrFeature[index].y1 - arrFeature[index].y0));
Thread.Sleep(100);///!!!/////在该处增加时间,不会出现异常
}
//grayPen.Dispose();
// userSetPen.Dispose();
////g.Dispose();
}
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-27 15:20
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社