• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1157
  • Last Modified:

notifyIcon not disappearing after closing the program

Hi,

I have notifyIcon icon control and it's working fine but not it's not disappearing when I close the the program.

How can this be fixed?

Thanks.
0
EEssam
Asked:
EEssam
  • 3
  • 3
1 Solution
 
DabasCommented:
Hello EEssam,

Are you sure your program is actually closing? (For example, have you checked in task manager -> Processes that its process actually has closed?

Regards,

Dabas
0
 
EEssamAuthor Commented:
Yes, I'm using Application.Exit() and as soon as I move the mouse over the icon it disappears.
0
 
Jaime OlivaresSoftware ArchitectCommented:
you need to dispose the NotifyIcon when terminating your application:

inside your Program class, do this:
           
static class Program
{
        [STAThread]
        static void Main()
        {      
                Application.ApplicationExit +=new EventHandler(Application_ApplicationExit);
                 // other tasks
        }
 
        static void Application_ApplicationExit(object sender, EventArgs e)
        {
            yourNotifyIcon.Dispose();
        }
}

Open in new window

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
EEssamAuthor Commented:
I got this error:

Error      1      The name 'notifyIcon' does not exist in the current context      D:\xxx\xxx\xxx\Program.cs      25      13      xxx
0
 
Jaime OlivaresSoftware ArchitectCommented:
That's depend on where is located your notifyIcon. How and where did you create it?
0
 
EEssamAuthor Commented:
I have a normal C# 2.0 Application. The Program.cs is created and a default form. My notifyIcon is located in my default form created in:
Application.Run(new FormFirst());

Open in new window

0
 
Jaime OlivaresSoftware ArchitectCommented:
better you put the notify icon in the program class.
But if you don't want, you can create a form's Closing event handle and dispose there.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now