In my WPF
including Caliburn.Micro
application, I want to show a new window to the user. This works fine for all the windows but for one. It throws an exception stating
The calling thread cannot access this object because a different thread owns it.
this is how I call the Window Manager
WindowManager.ShowWindow(new DatabaseCredentialsViewModel(EventAggregator, WindowManager,
SettingsManager));
Besides, I also tried to 'create a new Window Manager' by new WindowManager().ShowWindow(...);
. However, none of the above work. What is different from the other windows?
I started a new thread for the work in the background in OnViewLoaded
, from which I want to show a new window. The reason why I started a new thread in the first place is that by default, the GUI thread is the main thread and thus, if I don't start a new thread, the GUI isn't properly loaded until the code is executed (and so on).
Edit I: I investigated the problem and found out that it is not the Window Manager causing the trouble at this point, but perhaps new DatabaseCredentialsViewModel
, as I created a completely new Window Manager (a new instance of the original class) and it would still throw the same error.
Edit II: I tried this. However, the exact error persists.
Dispatcher.CurrentDispatcher.BeginInvoke((Action) (() =>
{
WindowManager.ShowWindow(new DatabaseCredentialsViewModel(EventAggregator, WindowManager, SettingsManager));
}));