user iconsosh on August 9th 2008
11498 views

topic iconBitmap and threads

Hi All,

Can anyone shed any light on whats going on here?

I have a windows form, which loads a bitmap stored in:

Bitmap bOriginalImage;

I then create a clost

Bitmap backBuffer = bOriginalImage();

this backbuffer is then used in the paint method to display the image in a panel on the form.

I then want to do some analysis on the original file in another thread, as such:

ThreadStart starter = delegate { da.analyse(bOriginalImage); };
Thread t = new Thread(starter);

During the analysis (which takes a few minutes) everything is fine, until something happens to cause the panel to be repainted.

Then I get a runtime error:

System.InvalidOperationException was unhandled
Message="Bitmap region is already locked."

I don't know why, because I assumed that the painting and the analysis were being done on separate copies of the bitmap.

What am I missing?!

Thanks

user iconVlasta on August 9th 2008 0

Just assigning the bitmap to another variable does not create a copy, try creating a copy explicitly using the Clone method. Maybe it will help.

user iconsosh on August 9th 2008 0

Sorry, I screwed up my original post. It should read:

I then create a clone

Bitmap backBuffer = bOriginalImage.clone();

That's what puzzles me!

user iconVlasta on August 9th 2008 0

In that case, I have no idea what could be wrong. Maybe the form still has a reference to the original somehow.

user icon