Bitmap and threads - RealWorld forums

Log-in or register.

Bitmap and threads

sosh
on August 10th 2008

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

Vlasta
on August 10th 2008

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.

sosh
on August 10th 2008

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

I then create a clone

Bitmap backBuffer = bOriginalImage.clone();

That's what puzzles me!

Vlasta
on August 10th 2008

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

Page views: 11435       Posts: 4      
Vista & Win 7 icons
I wish there were...
Select background