Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 155633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:11:24+00:00 2026-05-11T10:11:24+00:00

I am currently writing a WPF application which does command-line argument handling in App.xaml.cs

  • 0

I am currently writing a WPF application which does command-line argument handling in App.xaml.cs (which is necessary because the Startup event seems to be the recommended way of getting at those arguments). Based on the arguments I want to exit the program at that point already which, as far as I know, should be done in WPF with Application.Current.Shutdown() or in this case (as I am in the current application object) probably also just this.Shutdown().

The only problem is that this doesn’t seem to work right. I’ve stepped through with the debugger and code after the Shutdown() line still gets executed which leads to errors afterwards in the method, since I expected the application not to live that long. Also the main window (declared in the StartupUri attribute in XAML) still gets loaded.

I’ve checked the documentation of that method and found nothing in the remarks that tell me that I shouldn’t use it during Application.Startup or Application at all.

So, what is the right way to exit the program at that point, i. e. the Startup event handler in an Application object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:11:24+00:00Added an answer on May 11, 2026 at 10:11 am

    First remove the StartupUri property from App.xaml and then use the following:

        protected override void OnStartup(StartupEventArgs e)     {         base.OnStartup(e);          bool doShutDown = ...;          if (doShutDown)         {             Shutdown(1);             return;         }         else         {             this.StartupUri = new Uri('Window1.xaml', UriKind.Relative);         }     } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a WPF application which will monitor a feed. When there are new
I'm currently writing an application which uses ajax on the front end and ASP.NET
I am currently writing an application ( App1 ) which retrieves portions of text
I am currently writing a simple, timer-based mini app in C# that performs an
I'm currently writing an ASP.Net app from the UI down. I'm implementing an MVP
I'm currently writing a TYPO3 extension which is configured with a list of tt_content
I'm writing an application which will display the current image seen by a camera
I am working on an WPF application that uses a BusinessLogic layer (currently a
I am currently working on this application(C#,WPF,LINQ2XML,.NET 4.0) that displays details for 'Animals'. An
I am writing an WPF MVVM application using Prism. A couple days ago I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.