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

  • Home
  • SEARCH
  • 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 135197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:45:00+00:00 2026-05-11T06:45:00+00:00

I have an application that has been getting strange errors when canceling out of

  • 0

I have an application that has been getting strange errors when canceling out of a dialog box. The application can’t continue if the box is cancelled out of, so it exits, but it is not working for some reason, and thus it keeps running and crashes.

I debugged this problem, and somehow the application runs right past the Application.Exit call. I’m running in Debug mode, and this is relevant because of a small amount of code that depends on the RELEASE variable being defined. Here is my app exit code. I have traced the code and it entered the ExitApp method, and keeps on going, returning control to the caller and eventually crashing.

This is an application which provides reports over a remote desktop connection, so that’s why the exit code is a bit weird. Its trying to terminate the remote session, but only when running under release because I don’t want to shut down my dev machine for every test run.

    private void ExitApp()     {         HardTerminalExit();         Application.Exit();     }      // When in Debug mode running on a development computer, this will not run to avoid shutting down the dev computer     // When in release mode the Remote Connection or other computer this is run on will be shut down.     [Conditional('RELEASE')]     private void HardTerminalExit()     {         WTSLogoffSession(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, false);     } 

I’ve run a debugger right past the Application.Exit line and nothing happens, then control returns to the caller after I step past that line.

What’s going on? This is a Windows Forms application.

  • 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-11T06:45:01+00:00Added an answer on May 11, 2026 at 6:45 am

    This is an article which expands on the same train of thought you are going through: http://www.dev102.com/2008/06/24/how-do-you-exit-your-net-application/

    Basically:

    • Environment.Exit – From MSDN: Terminates this process and gives the underlying operating system the specified exit code. This is the code to call when you are using console application.

    • Application.Exit – From MSDN: Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed. This is the code to use if you are have called Application.Run (WinForms applications), this method stops all running message loops on all threads and closes all windows of the application. There are some more issues about this method, read about it in the MSDN page.

    Another discussion of this: Link

    This article points out a good tip:

    You can determine if System.Windows.Forms.Application.Run has been called by checking the System.Windows.Forms.Application.MessageLoop property. If true, then Run has been called and you can assume that a WinForms application is executing as follows.

    if (System.Windows.Forms.Application.MessageLoop) {   // Use this since we are a WinForms app   System.Windows.Forms.Application.Exit(); } else {   // Use this since we are a console app   System.Environment.Exit(1); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 102k
  • Answers 102k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To get the first tag for a file, use this:… May 11, 2026 at 8:11 pm
  • Editorial Team
    Editorial Team added an answer Use the function that PHP has for this purpose: $cmd… May 11, 2026 at 8:11 pm
  • Editorial Team
    Editorial Team added an answer Nice article on the subject of service broker management views… May 11, 2026 at 8:11 pm

Related Questions

I've run across an interesting PHP/SOAP error that has me stymied. After searching I
I have been getting an error message that I can't resolve. It originates from
I have an application for entering in serial numbers to a database. A serial
I recently rolled an application that automatically encrypted a file output from another internal

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.