Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

Formless Notify Icon Application

, 21 Apr 2007 CPOL
Shows notify icon, starting an app without a form, unhandled exception handling
notifychecker_demo.zip
STOPSIGN.ICO
TRAFFIC1.ICO
TRAFFIC2.ICO
TRAFFIC3.ICO
TRAFFIC4.ICO
VriServerManager.exe
notifychecker_src.zip
VriServerManager
bin
Debug
STOPSIGN.ICO
TRAFFIC1.ICO
TRAFFIC2.ICO
TRAFFIC3.ICO
TRAFFIC4.ICO
Properties
Settings.settings
VriServerManager.suo
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;

namespace VriServerManager
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            /**************************** Unhandeld exception catch ******************************************************
             * Create an handler that will be called by the framework when a unhandeld exception is detected
             *************************************************************************************************************/
            AppDomain myCurrentDomain = AppDomain.CurrentDomain;
            myCurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(myCurrentDomain_UnhandledException);

            /******************** 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 its actually used.
             * Note that Application.Run does not start any form
             * Application.SetCompatibleTextRenderingDefault() should not be called when there is no form
             * Checker is a Singleton
             *************************************************************************************/
            Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            Checker checker = Checker.GetCheckerObject();
            Application.Run();
            checker = null; //must be done to stop referencing Checker so GC can collect it.
        }

        static void myCurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            string error = "";
            try
            {
                Exception unhandeld = (Exception)e.ExceptionObject;
                error = "++++++++++++++++++++++++++++UNHANDELD EXCEPTION++++++++++++++++++++++++++++++++++++++++++++\r\n";
                error += DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss:fff") + "\r\n";
                error += "CLS Terminating = " + e.IsTerminating.ToString() + "\r\n";
                error += "------------------------------------------------------------------------------------------\r\n";
                error += "Exception:\r\n";
                error += "Message: " + unhandeld.Message + "\r\n";
                error += "Source:  " + unhandeld.Source + "\r\n";
                error += "StackTrace:  " + unhandeld.StackTrace + "\r\n";
                error += "==========================================================================================\r\n";
                error += "Innerexception Message: \r\n";
                if (unhandeld.InnerException != null)
                {
                    error += unhandeld.InnerException.Message + "\r\n";
                    error += "Source:  " + unhandeld.InnerException.Source + "\r\n";
                    error += "StackTrace:  " + unhandeld.InnerException.StackTrace + "\r\n";
                }
                error += "==========================================================================================\r\n";
                using (StreamWriter writer = new StreamWriter("unhandled.txt", true))
                {
                    writer.WriteLine(error);
                    writer.Flush();
                    writer.Close();
                }
            }
            catch (Exception more)
            {
                //even more misery
                MessageBox.Show(error + " additional problem: " + more.Message);
            }
            finally
            {
                //cleanup 
                if (e.IsTerminating)
                {
                    MessageBox.Show(error);
                }
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 21 Apr 2007
Article Copyright 2007 by mdv113
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid