Hanging .NET popup in callback from Java GUI with JNBridge

ChemAxon aa7c50abf8

16-10-2006 18:37:59

Quote:
I am developing a test application in .NET using Marvin and JNBridge. A Marvin View component is displayed as a .NET System.Windows.Forms.Form and when the user clicks on a "cell" of the Form containing the Marvin View component, an MSketch component should be displayed as another .NET Windows Form. My problem is that the MSketch component is halfway popped up, but then the entire application hangs.





Code:
public void mouseClicked(MouseEvent e)


{


    private MSketch popForm;





    if (popForm == null)


    {


        popForm = new Form1();


        popForm.Show();


    }


}
The thread that JNBridge uses on the .NET side to process callbacks from Java components is different, by default, from the one which started processing (on the Java side) the initiating event (mouse click). If the callback manipulates controls (Windows graphical components), the thread executing the callback on the .NET side is likely to try to access native resources which have been locked by the initiating thread on the Java side. In order to avoid deadlock, use the MView Form's BeginInvoke to defer creating the Windows Form:





Code:
public void mouseClicked(MouseEvent e)


{


    private MSketch popForm;





    if (popForm == null)


    {


        popForm = new Form1();


        BeginInvoke(new myDelegate(mSketch.Show));


    }


}









P.