Quantcast
Channel: R.NET
Viewing all articles
Browse latest Browse all 1634

New Post: Calling R.NET from another thread

$
0
0
Thank you.

I think the problem may be with COM marshalling, STA Thread etc.

Can you recommend a way how to create a new window safely?

My code is this:

[STAThread]
    public static void ShowRConsole()
    {
        var rAccess = new RAccess();

        if (!rAccess.CheckRWorks())
        {
            MessageBox.Show("R is not available!", ProductInformation.CompleteProductInformation, MessageBoxButton.OK, MessageBoxImage.Error);
            return;
        }

        var thread = new Thread(() =>
            {
                SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher));

                var window = new RConsole();

                System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(window);
                window.Show();

                window.Closed += (s, e) => Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);

                window.Show();

                Dispatcher.Run();
            });

        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();
    }

Viewing all articles
Browse latest Browse all 1634

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>