magicRoot Posted February 9, 2009 Posted February 9, 2009 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? Quote
Administrators PlausiblyDamp Posted February 9, 2009 Administrators Posted February 9, 2009 Is the other thread actually updating the UI? If so this is likely the problem as you should only update the UI from the UI thread. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
magicRoot Posted February 9, 2009 Author Posted February 9, 2009 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? Quote
magicRoot Posted February 9, 2009 Author Posted February 9, 2009 would calling a static function in the UI thread from the worker thread be considered thread-unsafe? Quote
magicRoot Posted February 12, 2009 Author Posted February 12, 2009 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.