System.InvalidOperationException thrown by System.Drawing

magicRoot

Newcomer
Joined
Jan 19, 2009
Messages
7
Hi
My Windows Forms program exits with the following error:

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Drawing.dll

Additional information: Object is currently in use elsewhere.

My program consists of a tabControl component with two tabs. The first tab has a picture box where I constantly place new images. The second tab has other stuff. Everything works fine when I remain in the first tab and continuously place images in the picture box, but if I switch to the second tab, then back to the first, I get the error stated. There is another thread apart from the UI thread that does the actual placement of images in the picturebox. What is causing the error?
 
yes, the worker thread does place the images in the picture box, but not directly; it uses a delegate method to call a setter function in the UI thread to change the image. I had the same error before due to the worker thread changing UI components directly. I added delegates to fix that. This error on the other hand is caused while in the UI thread. any ideas?
 
it seems that a method call in the worker thread was causing the exception. I think that method was making a system call internally, which was the source of the exception. Thanks for the hint.
 
Back
Top