Click here to Skip to main content
13,346,397 members (129,747 online)
Click here to Skip to main content
Add your own
alternative version


59 bookmarked
Posted 21 Apr 2007

Formless Notify Icon Application

, 21 Apr 2007
Rate this:
Please Sign up or sign in to vote.
Shows notify icon, starting an app without a form, unhandled exception handling


There are enough samples on notification icons, but most use third party components that contain the icon while .NET 2.0 offers a notification icon. Furthermore all sample applications start with a form that they show the user and keep in memory at all times. When the user closes the form, they hide it. I needed an application that only creates a form when the user needs to do some settings and closes the form without keeping it in memory. (Since the app was running on XPembedded where we need all the memory we can get free). This sample runs on XP as on XPembedded. It shows how to start an application without a form, and the use of the notification icon with a context menu to create and show a form to let the user do some settings. When the user is done, the form is removed from memory. It also shows how to make a class into a singleton and how to build an unhandled exception handler.

Using the Code

The code is only meant as an example. It does nothing useful. It does show how to start an application without a form (not hiding it!). This is rather simple (if you know how), simply change one line of code in the generated code in program.cs.

static void Main()
    /******************** NO Form *******************************************
    /* Here you create the class that will serve as the main
    * instead of loading the form and then hiding it. 
    * The class should call Application.Exit() when exit time comes.
    * The form will only be created and kept in memory when it's actually used.
    * Note that Application.Run does not start any form
    * Checker is a Singleton
    Checker checker = Checker.GetCheckerObject();
    //Application.Run(new Form1());
    checker = null; //must be done to stop referencing Checker so GC can collect it.

Using the notification icon is straight forward, it does not need a form:

notify = new NotifyIcon();
notify.Icon = iconstop;
notify.Text = "VriServerManager";
notify.ContextMenu = contextmenu;
//show form when double clicked
notify.DoubleClick += new EventHandler(notify_DoubleClick); 
notify.Visible = true;

A singleton is an object that can only have one instance in existence. One would choose a singleton when the object lives during the entire life span of the application and when the work done by the object only makes sense when done by one instance. You can make a class a singleton by making the constructor private, instantiate it during the first reference and add a method that enables other objects to obtain a reference to it.

Like so: Private variable to instance:

private static readonly Checker checker = new Checker();

Private constructor:

private Checker() //singleton so private constructor!

Method to get reference:

public static Checker GetCheckerObject()
    return checker;

Points of Interest

This application contains code to catch exceptions that are not caught by the application itself. Usually this will result in an unhandled exception message box with information that is almost impossible to interpret. When using the unhandled exception event, you can get the information you desire like the line number where the problem originates from. This is all you need to do in the main...

AppDomain myCurrentDomain = AppDomain.CurrentDomain;
myCurrentDomain.UnhandledException += 
    new UnhandledExceptionEventHandler(myCurrentDomain_UnhandledException);

The handler...

static void myCurrentDomain_UnhandledException
    (object sender, UnhandledExceptionEventArgs e)
    //get error info here, see program.cs


  • 21-04-2007: First draw


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer Siemens
Netherlands Netherlands
Windows/Web developer for Windows Or embedded.
Started with ASM85 / PLM85
Then C and C++ (STL)(Windows / Linux)
Now mostly working with .net C# / VB
ASP.NET and ADO.NET and some SQL (sql 2000 & 2005)

You may also be interested in...


Comments and Discussions

Generalvery cool Pin
mboiciuc7-Nov-08 5:30
membermboiciuc7-Nov-08 5:30 
GeneralRe: very cool Pin
mdv1137-Nov-08 12:36
membermdv1137-Nov-08 12:36 
GeneralA little improvement Pin
Antonio David Gonzlez26-Sep-08 5:47
memberAntonio David Gonzlez26-Sep-08 5:47 
When the application terminates, the icon remains in the tastkbar until the mouse pointer moves over the icon. To prevent this, you can call: notify.Visible = false; Just before you stop the timer on the Dispose() method.
GeneralRe: A little improvement Pin
mdv11326-Sep-08 6:07
membermdv11326-Sep-08 6:07 
QuestionTooltip and BalloonTips not show. Pin
qjchen28-Mar-08 12:35
memberqjchen28-Mar-08 12:35 
AnswerRe: Tooltip and BalloonTips not show. Pin
mdv1131-Sep-08 23:55
membermdv1131-Sep-08 23:55 
Generalsimilar Pin
AlexHaan26-Apr-07 23:20
memberAlexHaan26-Apr-07 23:20 
AnswerRe: similar Pin
mdv11327-Apr-07 0:53
membermdv11327-Apr-07 0:53 
GeneralRe: similar Pin
Gigio2k3-Oct-08 10:49
memberGigio2k3-Oct-08 10:49 
GeneralRe: similar Pin
mdv1135-Oct-08 21:00
membermdv1135-Oct-08 21:00 
GeneralNice Article Pin
The Code Guru21-Apr-07 23:08
memberThe Code Guru21-Apr-07 23:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 21 Apr 2007
Article Copyright 2007 by mdv113
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid