Reputation: 53
I have an application where at one point I am closing all windows and I want to relaunch one of the closed windows. But the problem is when I say Window.Show();
the breakpoint shows the Actual Height and Actual Width to be 0 and after the line is executed, the entire app shuts down. Why, is it being garbage collected?
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
if (jsonAssayViewModel.IsLiveProgress)
{
var res = Xceed.Wpf.Toolkit.MessageBox.Show(
Application.Current.TryFindResource("CloseRun").ToString(),
"Confirm dialog",
MessageBoxButton.YesNo,
MessageBoxImage.Question
);
if (res == MessageBoxResult.No)
{
jsonAssayViewModel.PreventClosingWindow = true;
return;
}
}
//Raise the close event....
if (CloseCurrentProgressWindow != null)
{
CloseCurrentProgressWindow();
}
var window = Window.GetWindow(this);
if (window != null && window.Tag.ToString() == "Success")
{
if ((sender as Button).Content.ToString() == Application.Current.TryFindResource("Done").ToString())
{
var AllWindows = Application.Current.Windows.Cast<Window>()
.Where(win => win.IsLoaded);
if (AllWindows.Count() > 2)
{
jsonAssayViewModel.SelectedAssay = null;
jsonAssayViewModel.SelectedVolume = string.Empty;
foreach (Window win in App.Current.Windows)
{
win.Close();
}
NextGenDGRunSetupWindow wn = new NextGenDGRunSetupWindow();
wn.Show();
}
}
}
}
And in the NextGenDGRunSetupWindow I have the following
public NextGenDGRunSetupWindow()
{
InitializeComponent();
//idleTimeDetector = new IdleDetector(this); //1 minute
readJsonViewModel = ReadJsonAssayViewModel.ReadJsonAssayViewModelInstance;
//idleTimeDetector.IsIdle += IdleTime_IsIdle;
readJsonViewModel.LaunchErrorWindowFromAnywhere += ReadJsonViewModel_LaunchErrorWindowFromAnywhere;
}
Upvotes: 0
Views: 72
Reputation: 32072
The problem is that you are closing every Window that's loaded in your application. Since Show()
does not block, the moment the method finishes executing the startup Window closes and your application exits. You have a couple of options here:
wn.ShowDialog();
- this blocks the current method until the window is closed; orforeach
.Application.ShutDownMode
to either ShutDownMode.OnExplicitShutdown
or ShutDownMode.OnLastWindowClose
Upvotes: 2