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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:03:53+00:00 2026-05-24T06:03:53+00:00

This is a C# app that sits in the tray as a notifyicon and

  • 0

This is a C# app that sits in the tray as a notifyicon and does its stuff until someone right clicks it and selects close (menu option) or it gets a wm_close from an external app or by the operating system say during a reboot.

protected override void WndProc(ref Message m)
{
   case  Win32.WmClose:
  //recvd message to shutdown
   Program.Log.InfoFormat("Shutdown received at {0}", DateTime.Now);
   CleanUp();
   this.Close(); //this is the main form
   break;

   //other case statements here
}

//somewhere else on menu exit of notify icon
 private void toolStripMenuItemExit_Click(object sender, EventArgs e)
 {
        Program.Log.InfoFormat("Manual EXIT at {0}", DateTime.Now);
        CleanUp();
        this.Close(); //this is the main form
 }

The this.close() triggers another WM_CLOSE sending the app in a tailspin. What is the correct way to handle this situation ? thank you

  • 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-24T06:03:54+00:00Added an answer on May 24, 2026 at 6:03 am

    Handle form Closing event. and whenever you want to exit just call Close();, and make any other operation rely on closing inside the closing event instead of handling it at WndProc and toolStripMenuItemExit_Click, so:

    private void OnFormCloseing(object sender, FormClosingEventArgs e)
    {
        string reason = string.Empty;
        switch (e.CloseReason)
        {
            case CloseReason.UserClosing:
                reason = "Manual EXIT";
                break;
    
            case CloseReason.WindowsShutDown:
                reason = "Shutdown received";
                break;
        }
        Program.Log.InfoFormat(reason + " at {0}", DateTime.Now);
        CleanUp();
    }
    
    private void toolStripMenuItemExit_Click(object sender, EventArgs e)
    {
        this.Close(); //this is the main form
    }
    

    More members of CloseReason here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this app that all it does is perform selects and after I'm
An example of an app that does this is Enso , it pops up
I have a small app that has a Render thread. All this thread does
I have a c# .net app. So I created a notifyIcon that sits in
I want to write a small app that sits in my tray and that
I'm writing a text entry app that sits in the System Tray and assists
I have a simple GAE app that includes a login/logout link. This app is
I have this .NET web app that draws a table in Page_Load. Then after
I have this c# web app that relies heavily on two dll files that
So I'm working on this site web app that should let users easily chat

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.