Repost: Maybe a GoBug: invoke or

Some time ago I posted something about creating another view out of a view already shown.

i.e. Clicking on a graphical element contained in the main GoView will open another view in a form contained in the graphic element itself.



I didn’t know how to solve the problem till yet.



You just have to lock the block with the type of your called form as parameter given to the lock command.

i.e. form is of type “FormShowActivitySet”

then you would have to call:



lock(typeof(FormShowActivitySet))

{



Reproducing just seems to be easy like this:



Create a project with a view in it (likely an mdi container app), then on right click on of the elements

in the view, open another form showing a view contained in the element, e.g.:



class GraphNode

{

GraphView gvView = new GraphView();



//call this on ContextClick

public void Open()

{

Form frm = new FormShow(gvView);

frm.ShowDialog();

}

}



this should reproduce the error.



//Lock, because of occasional crashes

lock(typeof(FormShowActivitySet))

{

//Kein AutoLayout

FormShowActivitySet.DoAutoLayo ut = false;

MainForm.App.OpenedActivitySet GraphView = this.InnerView;

FormShowActivitySet frmShowActivitySet = new FormShowActivitySet(this);

if (!frmShowActivitySet.Created && !frmShowActivitySet.IsHandleCreated)

{

System.IntPtr iHandle = frmShowActivitySet.Handle;

MainForm.App.LastOpenedActivitySet = this;

frmShowActivitySet.ShowDialog();

}

}

Attention this may not be the case in general,

look in google: there are many reasons that could create this exception.



And another hint: this exception may not be handled correctly in your application, even if the code causing it is contained in a try…catch-block.

OK, I was able to cause the error to happen occasionally.
However, I cannot understand how it could happen that the Control is getting events when it (actually its Windows Handle) hasn’t been created yet. Well, we can guard against that. Ugh–yet another reason why defining Controls isn’t something for the casual programmer.

Ok, so what should I do now to prevent this error?



the solution described above will be not that bad,

but in betweem I found out that the error still happens to occur sometimes, but a bit more seldom.

You’ll need to use GoDiagram Win 2.2.0 beta 2.