I'm developing application with C#, Net 4.5.2 and WPF. It has remotely controlled GUI, so incoming HTTP GET
requests (handled with Nancy) trigger some changes in Window
s. Since server isn't running in GUI thread, I'm using Dispatcher.Invoke
to call graphic changing methods. And there I get really weird behavior: if Show
was not called for my Window
, nothing happens. But calling Show
creates 2 windows instead of one. How can I fix it?
public partial class App : Application //App.xaml.cs
{
public static MainWindow mainWindow;
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
mainWindow = new MainWindow();
//REMOVING NEXT LINE COMPLETELY BREAKS DISPATCHER.INVOKE IN mainWindow
mainWindow.Show();
}
}
public class MainModule : Nancy.NancyModule //Nancy server module
{
public MainModule()
{
Get["/stop"] = param => App.mainWindow.StopContent();
}
}
public partial class MainWindow : Window //WPF window
{
public MainWindow()
{
InitializeComponent();
}
public void StopContent()
{
//LINE BELOW WON'T WORK IF Show WASN'T CALLED
Dispatcher.Invoke(new Action(() => { Background = null; }));
}
}