We’ve been getting several ‘Object is currently in use elsewhere’ errors thrown by the System.Drawing library when loading GoView. To alleviate this problem we tried putting locks around the loading of GoView, which has decreased the amount of these errors. The problem still occurs, but not as often. Any suggestions?
When are the exceptions happening? They are being raised by GDI+ code, of course, but is it your code that is manipulating pens or brushes or bitmaps, or is it GoDiagram code?
There is a fair bit of locking that GoDiagram Web does internally, to avoid exactly those problems. But I suppose we might have missed some case.
It’s also less likely to happen in your code with GoDiagram version 3, where explicit manipulation of brushes, for example, is not needed in most common cases.
The exception occurs when the page is loading and creating GoObjects to be added onto the GoDocument. While it is loading I set link and node colors by statements like the following:
this.Pen = new Pen(Color.Chartreuse, 6);
this.Brush = Brushes.Chartreuse;
Does this count as our code manipulating the pens and brushes?
Should I be putting locks around these statements?
My code executes on the Page_Load event of a modal dialog popup.
The locking looks like this:
if (Page.IsPostBack == false)
{
State.View = new GoView(); //State.View is a reference to a session variable that stores the GoView
lock (State.View)
{
Add everything that needs to be added onto the GoDocument.
}
}
Also the GoView is not added to a page, it is just loaded in the background.