I'm trying to close a WPF window I created in a separate thread from the main hosting thread (The main thread is of a PDM application that I have no control over). The host application references my assembly (it's a plugin). I don't know but why the Dispatcher is always null. Creating the WaitView on the host application is not an option for me.
Thanks guys!
    var WaitViewModel = new MVVM.ViewModels.WaitViewModel();
                        MVVM.Views.WaitView WaitView = default(MVVM.Views.WaitView);
                        Dispatcher dispatcher = default(Dispatcher); 
                        var thread = new Thread(new ThreadStart(() =>
                        {
                            dispatcher = Dispatcher.CurrentDispatcher; 
                            WaitView = new MVVM.Views.WaitView();
                            WaitView.Topmost = true;
                            WaitView.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                            WaitView.DataContext = WaitViewModel;
                            WaitView.Show();
                            System.Windows.Threading.Dispatcher.Run();
                        }));
                        thread.SetApartmentState(ApartmentState.STA);
                        thread.IsBackground = true;
                        thread.Start();
'unrelated code here
if (dispatcher != null)
dispatcher.Invoke(()=>
{
WaitView.Close();
});
 
    