khrabrovart
khrabrovart

Reputation: 179

WPF main window does not return

The problem is that my program does not return after return; statement. Maybe I am just tired and cannot find obvious mistake but... it continues its work after Return and opens the window. What the heck?

And yes, my program enters IF statement.

public partial class MainWindow : Window
{
    public MainWindow()
    {
        bool checkingResult = FileChecker.CheckFiles();
        if (!checkingResult)
        {
            MessageBox.Show("Required files are missing.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            return;
        }

        InitializeComponent();
        DataContext = new MainViewModel();
    }
}

Upvotes: 0

Views: 181

Answers (1)

Patrice Gahide
Patrice Gahide

Reputation: 3744

MainWindow() is just a constructor. The application doesn't terminate when this constructor returns. Use Application.Current.Shutdown() to properly close a WPF app.

Upvotes: 5

Related Questions