Thread t1;
Thread t2;
int count1 = 0;
int count2 = 0;
static readonly object olock = new object();
public Bitmap bitmapVal = new Bitmap(@"C:\Users\BEIYUTECH\Desktop\th.jpg");
public Bitmap BitmapVal
{
get
{
lock (olock)
{
return (Bitmap)bitmapVal.Clone();
}
}
}
private void button1_Click(object sender, EventArgs e)
{
t1 = new Thread(getBitmap1);
t1.Start();
t2 = new Thread(getBitmap2);
t2.Start();
}
private void getBitmap1()
{
while (true)
{
count1++;
this.pictureBox1.Image = this.BitmapVal;
}
}
private void getBitmap2()
{
while (true)
{
count2++;
this.pictureBox2.Image = this.BitmapVal;
}
}
出错代码行:this.pictureBox1.Image = this.BitmapVal;或者this.pictureBox2.Image = this.BitmapVal;
错误信息:
“System.InvalidOperationException”类型的未经处理的异常在 System.Drawing.dll 中发生
其他信息: 对象当前正在其他地方使用。
已经使用了lock为什么没有效果,还是说我用发错了或者其他原因。请各位大大不吝赐教!谢谢~