Hi,
I have an application and this application needs to display a message when the window shutdown happen. How can i detect that the system is shutting down from a C# program
Code:
namespace ConsoleApplication1
{
public partial class Program
    {
        static void Main(string[] args)
        {

            string regMatch = "";//string to search for inside of text file. It is case sensitive.
            string readtext = "";
            string path = "";
            bool persistantfilepresent = false;
            bool status = false;
            try
            {
                readtext = readroutetable(); // Read the windows routing table

                //path = "d:\\file.txt";
                //deletefiles(path); //Delete the  output dump file

                path = "d:\\madavas1.txt";
                deletefiles(path);  //delete madavas1 files 
                createfiles(path);  // Create a file to write to madavas1.txt.

                path = "d:\\madavas2.txt";
                deletefiles(path); //delete madavas2 files 
                createfiles(path);  // Create a file to write to madavas2.txt.

                path = "d:\\madavas1permanent.txt";
                createfiles(path);  // Create an empty file for storing the peristant route

                regMatch = "Active Routes:";
                ActiveRoutes(regMatch, readtext);//create mdavas1.txt for persistent route

                regMatch = "Persistent Routes:";
                Persistentroute(regMatch, readtext);//create mdavas2.txt for active route


                readrange();           
                currentgateway();           // Read current gateway values

                status = comparerange();       
                              }


                persistantfilepresent = checkpersitantroute();     
                writepersistantroute();
// Here I want a while loop to check whether the system shut down is there  
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} Exception caught.", e);
                Console.ReadLine();
            }
        }
}