Calling MessageBox.Show() from COM .NET library from Ruby closes SketchUp


#1

Hi all,

We are writing an extension on Ruby for SketchUp 2015 x64. This extension will work with our COM object. The COM object is .NET library.

.NET simply calls Windows Forms

MessageBox.Show();

but this lines closes SketchUp. While debugging I get next exception message

Exception of type 'System.ExecutionEngineException' was thrown.

and SketchUp is closed. If I call the same method as COM object from .NET simple console application all works fine.

Have you met with this kind issues before? Maybe you know a better way to call .NET functions from Ruby extension.

Any help is appreciated.

Best regards, Vladimir


#2

You can use the Ruby wrapper for the system messagebox function:
http://www.sketchup.com/intl/en/developer/docs/ourdoc/ui.php#messagebox

msg = "Some text message we display to user."
UI.messagebox( msg, MB_OK )

#3

Hi Vladimir,

You need to call the MessageBox.Show(); within another thread.
for example:

        Dispatcher dispatcher = Dispatcher.CurrentDispatcher;

        Thread thread = new Thread(() =>
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            lock (windowLock)
            {
                _mainWpf = new SODMainWindow(this, dispatcher);
            }

            _mainWpf.Closed += (sender2, e2) =>
            {
                _mainWpf.Dispatcher.InvokeShutdown();
            };
            _mainWpf.Show();

            System.Windows.Threading.Dispatcher.Run();
        });