I am currently using an UltraWinToolbar. We are - very infrequently - seeing the Exception below come up from the OnPaint of the toolbar. What I suspect is happening is that I am using a single Appearance object as the appearance for two different tools, and there sometimes is a race condition as the two try to access the same image at the same time. I plan to switch to using two different appearances which reference the same image, but since this is not at all an easily reproducible issue, it's also not a fix which I can verify with much confidence.
So I thought I'd ask the experts - have you seen an issue like this before? Should I avoid using the same appearance object for more than one tool? Does this fix seem plausible to avoid this rare, timing-sensitive exception?
It's also possible the race condition is for the bitmap object wrapper, or even further down in the ResourceManager.
appearanceEmail = new Infragistics.Win.Appearance();
appearanceEmail.Image = global::FrontendControls.Resources.FrontendControlsResources.email;
appearanceEmail.ForeColor = System.Drawing.SystemColors.ControlText;
--------------------------
System.InvalidOperationException: Object is currently in use elsewhere. at System.Drawing.Image.get_Width() at System.Drawing.Image.get_Size() at Infragistics.Win.UltraWinToolbars.PopupToolDropDownButtonUIElement.PositionChildElements() at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean clipText, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics) at Infragistics.Win.UIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize, Boolean preventAlphaBlendGraphics) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) at Infragistics.Win.UltraControlBase.OnPaint(PaintEventArgs pe) at Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea.OnPaint(PaintEventArgs pe) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Based on another dev's suggestion here, I hacked a workaround to this by testing specifically for this error code when my code changes the enabled state on a button, and if the error occurs, pause a tenth of a second and retry. I put that in a loop up to five times, but have only ever seen it take one retry. Very ugly. And I don't think very reliable, since if someone else's code (Infragistics, or .NET) triggers this problem, it's unpredictable where in my own code the error might be raised. I can't realistically check for and retry this everywhere in our (large) code base.
I have the same problem, and I just submitted a bug report to their people as per Mike Dour's suggestion. :)
Hi!
I have the same problem and i dont use multithreading. Has there been any solution to the problem?
Are you using the image on forms which are on different threads? If so, it is definitely possible that is what's causing the error and I would recommend cloning the image to use on different threads. If not, I'm not sure what would cause the issue, but I don't think it would be caused by using the same appearance on two tools, so I'm not sure if fixing that would help. If your application is not multi-threaded I would submit the issue to the support group: http://ko.infragistics.com/gethelp.