Object is currently in use elsewhere

We are using GoWeb 2.6.2

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?

Thanks,
J

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?

Thanks,
J

Can you tell if the exception is actually coming from that Pen assignment statement?

From the stack trace I can only narrow it down to a function that sets the Brush property of a GoTextNode to a saved Brush property I created earlier.

For example:
public Brush CommitColor = Brushes.White;

function ()
{
this.Brush = CommitColor;
}

I’m also doing something like this:
function ()
{
this.Brush = brush;
myOldBackgroundBrush = this.Brush;
}

Exactly when does your code execute?

What locking did you try to do?

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.

I suppose you could try a blunt instrument:

lock (typeof(GoView)) {
… construct the document and render the view …
}

Since you aren’t adding the GoView control to your page, I assume you are creating it just to render an image.

I’ll give that a try. I haven’t seen the problem occur in the past few days, but that may be due to the variation on server load.

Thanks for the help. If it keeps occurring I’ll post again.

J