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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:03:21+00:00 2026-06-17T00:03:21+00:00

I have an application that has a main form and a system task tray

  • 0

I have an application that has a main form and a system task tray icon. In the designer of the main form, I dragged the TrayIcon control on the form, so it is a child of the main form.

At this point, when the user presses the close button on the main form, it actually just hides it so that the application wont terminate, unless the user right clicks the TrayIcon and clicks exit. But, the main form has a lot of controls and resources, and when the main form is hidden, it still uses memory for those resources. My goal is to actually dispose of form so it doesn’t take up that memory while it is not being used.

Unless I am mistaken, and when the main form is hidden it doesn’t take up that memory anymore, but I don’t think that is the case.
I’m no expert on memory, I may even be completely mistaken on how memory management works, and thus this question is invalid.

Anyways, if I am correct in that when the main form is only hidden it still takes up memory that can be freed by fully closing the form, is there a way for me to actually close the main form without the application terminating? If so, I would need to create the TrayIcon with code in the Program class instead of in the class of the main form, correct?

  • 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-06-17T00:03:23+00:00Added an answer on June 17, 2026 at 12:03 am

    No, that’s certainly not necessary. It is encouraged by the convenience of the designer but you can easily create an application that only creates a window on demand. You’ll have to write code instead. It doesn’t take a heckofalot, there’s a sample app with basic functionality. Edit the Program.cs file and make it look similar to this (icon required, I called it “SampleIcon”):

    static class Program {
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var cms = new ContextMenuStrip();
            cms.Items.Add("Show", null, ShowForm);
            cms.Items.Add("Exit", null, ExitProgram);
            var ni = new NotifyIcon();
            ni.Icon = Properties.Resources.SampleIcon;
            ni.ContextMenuStrip = cms;
            ni.Visible = true;
            Application.Run();
            ni.Dispose();
        }
    
        private static void ShowForm(object sender, EventArgs e) {
            // Ensure the window acts like a singleton
            if (MainWindow == null) {
                MainWindow = new Form1();
                MainWindow.FormClosed += delegate { MainWindow = null; };
                MainWindow.Show();
            }
            else {
                MainWindow.WindowState = FormWindowState.Normal;
                MainWindow.BringToFront();
            }
        }
    
        private static void ExitProgram(object sender, EventArgs e) {
            Application.ExitThread();
        }
    
        private static Form MainWindow;
    }                                                                
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Delphi application that has a document browser as the main form.
I have an application with a form that has a main menu. Now I
I have an application that has a few different forms. From the main form
I have an application that has a main form and uses an event handler
I have an application that has two threads. The first one (the main thread)
In my application I have several activities, the main screen has 4 buttons that
I have a Visual C# 2010 application, and it has one main form called
I have a window form application, and it has multiple threads running that would
I am working on a form application that has two windows. In the main
I have a form in a vb.net windows form application called PolicyRefreshStatus.vb that has

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.