Original Post
(Just started learning C#, .Net, Forms.)
I have a form with a custom PictureBox (i.e inherited from PictureBox), with a new method Transition(). In Transition I hand the work off to a work thread and return immediately so the UI doesn''t hang. In the work thread I draw on PictureBox.Image and call PictureBox.Invalidate() in a finite loop to see the results as they occur.
I kept getting a "The object is currently in use elsewhere." prompt and a break on the PictureBox.Image object or it''s associated Graphics object and have come to find out that controls should not be manipulated in threads other than the ones that created them. That''s the dilemma.
So instead of calling this.Invalidate after drawing on this.Image (this being my custom PictureBox), I did this.Draw(), Draw() being the following:
delegate void HelperDelegate();
private void Draw()
{
if (this.InvokeRequired)
this.Invoke(new HelperDelegate(this.Draw));
else
this.Invalidate();
}
...but I still get the same problem when accessing Image, which means that I can''t touch any part of PictureBox within the work thread, even Image, which you would think is equivalent to any other memory bitmap, but I guess PictureBox tries to access it over in the main thread from time to time to update itself while I''m drawing on it. This makes asynchronous drawing in another thread very very difficult.
Does anyone have any suggestions? The only thing I can think of is that I should run the message pump in the drawing loop all in the main thread... though I''m not quite sure how to manually call the message pump using Forms... :/
Thanks in advance to anyone who can help.
------------
- outRider -