views:

1036

answers:

2

I think this is a bug in the WPF framework, with out going into depths of my program and why I am doing what I am doing, I wrote a simple test app to prove my theory.

Can someone confirm this issue, and suggest possible work arounds for a series of dialogs to be executed before putting the app into its run loop?

using System;
using System.Collections.Generic;
using System.Configuration; 
using System.Data;
using System.Linq;
using System.Windows;

namespace ShowDialogWindow
{
  /// <summary>
  /// Interaction logic for App.xaml
  /// </summary>
  public partial class App : Application
  {
    protected override void OnStartup(StartupEventArgs e)
    {
       Window testWindow = new Window();
       testWindow.ShowDialog();
       testWindow.Close();
       // THE CODE BELOW WILL NOT SHOW THE NEXT WINDOW
       Window testWindow2 = new Window();
       testWindow2.ShowDialog();
       testWindow2.Close();
    }
  }
}
+4  A: 

Not a bug. The default ShutdownMode of Application is OnLastWindowClosed, so as soon as the first window is closed your application will start shutting down! Change to OnExplicitShutdown and it will work, but you'll have to manage the shutdown.

I think you probably just need to rethink what you're actually trying to achieve. Why would you display two subsequent dialog windows during the startup of your app?

HTH, Kent

Kent Boogaart
A: 

Sure I can change my design to accomadate this behaviour. What i was trying to do was really simple however.

I have deriverd my MyApplication from Application, on the Main(),I innitiate a series of start checks, for example, license information, splash screen, connectivity and configuration checks, ect. When I get my all clear, I call MyApplicatiom.Run(MyMainForm),

This design is based on a normal Windows application which works with out a problem.

Thanks a lot for your help, and I will remember that you cannot call ShowDialog() before application.Run() as it simply innitializes a shut down. I would have thought however that a shutdown sequence should only be innitiated after a App.Run() instruction.

Please correct me if I am understanding this wrong.

Like Kent said, all you have to do is go into App.xaml and set `ShutdownMode="OnExplicitShutdown"`, then handle the `Closed` event of your main form and call `App.Current.ShutDown()`.
Joel B Fant