各pictureBox_rightとpictureBox_leftのセットの次のコードは、オブジェクトが別の場所で使用されているというエラーを表示しています。私はこれをどのように修正するのだろうと思っていた。スレッディングバグを修正する方法
private Bitmap pictureBox_right
{
get
{
lock (lockObject)
return (Bitmap)this.pictureBox_rightConnectivity.Image.DeepClone();
}
set
{
lock (lockObject)
{
pictureBox_rightConnectivity.Image = value.DeepClone();
}
}
}
private Bitmap pictureBox_left
{
get
{
lock (lockObject)
return (Bitmap)this.pictureBox_leftConnectivity.Image.DeepClone();
}
set
{
lock (lockObject)
{
this.pictureBox_leftConnectivity.Image = value.DeepClone();
}
}
}
次のエラーが原因となるコードの行です:これはエラーが、それは本質的には同じですが、左のピクチャボックスのためにそれをしない別の部分である
Bitmap copy;
lock (ArduinoUno_v1.Properties.Resources.on_button)
{
copy = new Bitmap(ArduinoUno_v1.Properties.Resources.on_button);
pictureBox_rightConnectivity.Image = new Bitmap(ArduinoUno_v1.Properties.Resources.on_button);
//pictureBox_right = ArduinoUno_v1.Properties.Resources.on_button;
}
pictureBox_right = copy;
。
Bitmap copy;
lock (ArduinoUno_v1.Properties.Resources.on_button)
{
copy = new Bitmap(ArduinoUno_v1.Properties.Resources.on_button);
pictureBox_leftConnectivity.Image = new Bitmap(ArduinoUno_v1.Properties.Resources.on_button); // making a copy so we don't get into access problems
// pictureBox_left = ArduinoUno_v1.Properties.Resources.on_button;
}
pictureBox_left = copy;
私はこれをどのように修正するのですか。私の考えていることは、特定の機会に、私のpictureBox_rightconnectivity.ImageとpictureBox_leftconnectivity.Imageがまだ別のスレッドによってアクセスされているということです。別のスレッドが入ってきて、そのイメージを設定しようとします。私はこれをどのように修正するのだろうと思っていたのですか?私の最初の試みは、ビットマップコピーオブジェクトでイメージをコピーしようとすることでした。それを使ってpictureBox_leftとpictureBox_rightを設定します。しかし、私はこれがまだオブジェクトが他のエラーで使用されていることが判明した。