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]
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();
}