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 6712583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:16:36+00:00 2026-05-26T08:16:36+00:00

I have a winforms program which have an Exit button which fires an event

  • 0

I have a winforms program which have an “Exit” button which fires an event that performs a clean up and then afterwards fire Application.Exit(); to exit the program.

But since the program is a tray application, I often forget to shut down the program using this exit button and just hitting the Windows shutdown instead. If I do that the event is not called and therefore not cleaning up.

My question is: Is there an event I can count on when using different closing methods, like windows shutdown?

I have seen I can override OnClosing – but is this the correct way?

Edit:

All answers did work. But I eventually ended out with:

Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
  • 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. Editorial Team
    Editorial Team
    2026-05-26T08:16:36+00:00Added an answer on May 26, 2026 at 8:16 am

    Yes, to find different closing methods overriding the OnClosing event will work. Look at the below code part.

            protected override void OnFormClosing(FormClosingEventArgs e)
            {
                try
                {
                    ConfirmClose = true;
                    base.OnFormClosing(e);
                    if (e.CloseReason == CloseReason.WindowsShutDown)
                   {
                        //Do some action
                   }
                }
              }
                catch (Exception ex)
                {
    
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a winforms application that normally is at about 2-4% CPU. We are
We have a WinForms application written in C# that uses the AxAcroPDFLib.AxAcroPDF component to
I have C# winforms application that needs to start an external exe from time
I have build an C# Winforms application which will need regular updates and patches
In my WinForms application I have a timer which 'ticks' every second. In the
I have written a WinForms program in C#.Net to click a button programmatically within
I have created a .NET C# WinForms application on Win 7 RTM x64, which
I have a .NET winforms program that includes a feature to launch a specific
I have been working on a C# WinForms application that registers several hot keys
How can I have a WinForms program do some specific thing whenever a certain

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.