{"id":2645,"date":"2022-08-30T15:26:35","date_gmt":"2022-08-30T15:26:35","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/04\/how-to-exit-a-wpf-app-programmatically-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:26:35","modified_gmt":"2022-08-30T15:26:35","slug":"how-to-exit-a-wpf-app-programmatically-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-exit-a-wpf-app-programmatically-collection-of-common-programming-errors\/","title":{"rendered":"How to exit a WPF app programmatically?-Collection of common programming errors"},"content":{"rendered":"<p>As wuminqi said, <code>Application.Current.Shutdown();<\/code> is irreversible and I believe it is typically used to force an application to close at times such as when a user is logging off or shutting down Windows. Instead, call <code>this.close()<\/code> in your main window. This is the same as pressing &#8220;ALT-F4&#8221; or the close [x] button on the window. This will cause all other owned windows to close and will end up calling <code>Application.Current.Shutdown();<\/code> so long as the close action wasn&#8217;t cancelled. Please see the MSDN documentation on Closing a Window.<\/p>\n<p>Also, because <code>this.close()<\/code> is cancellable you can put in a save changes confirmation dialog in the closing event handler. Simply make an event handler for and change <code>e.Cancel<\/code> accordingly. (See the MSDN doc for more details on how to do this)<\/p>\n<p id=\"rop\"><small>Originally posted 2014-02-04 12:12:12. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>As wuminqi said, Application.Current.Shutdown(); is irreversible and I believe it is typically used to force an application to close at times such as when a user is logging off or shutting down Windows. Instead, call this.close() in your main window. This is the same as pressing &#8220;ALT-F4&#8221; or the close [x] button on the window. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2645","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2645"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2645\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}