Changeset 1054


Ignore:
Timestamp:
05/11/09 10:39:43 (5 years ago)
Author:
lowjoel
Message:

Always call the OnExitInstance? function. When the systme is shutting down it doesn't get called before. Now we chain up with the main form so that even if shutdowns are ordered we get a chance to clean up/do whatever post-application run processing we need to do.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/Eraser/Program.cs

    r1013 r1054  
    299299            //If no other instances are running, set up our pipe server so clients 
    300300            //can connect and give us subsequent command lines. 
    301             if (IsAlreadyRunning) 
     301            if (IsFirstInstance) 
    302302            { 
    303303                try 
     
    308308 
    309309                    //Initialise and run the program. 
    310                     if (OnInitInstance(this) && MainForm != null) 
     310                    bool ShowMainForm = OnInitInstance(this); 
     311                    if (MainForm == null) 
     312                        return false; 
     313 
     314                    //Handle the exit instance event. This will occur when the main form 
     315                    //has been closed. 
     316                    mainForm.FormClosed += OnExitInstance; 
     317 
     318                    if (ShowMainForm) 
    311319                        Application.Run(MainForm); 
    312320                    else 
     
    318326                        Application.Run(); 
    319327                    } 
     328 
    320329                    return true; 
    321330                } 
    322331                finally 
    323332                { 
    324                     //Since the program was initialised we must let the program clean up. 
    325                     OnExitInstance(this); 
    326333                    pipeServer.Abort(); 
    327334                } 
     
    455462        /// Gets whether another instance of the program is already running. 
    456463        /// </summary> 
    457         public bool IsAlreadyRunning 
     464        public bool IsFirstInstance 
    458465        { 
    459466            get 
     
    467474        /// run is called if it is non-null and if its Visible property is true. 
    468475        /// </summary> 
    469         public Form MainForm 
    470         { 
    471             get 
    472             { 
    473                 return mainForm; 
    474             } 
    475             set 
    476             { 
    477                 mainForm = value; 
    478             } 
    479         } 
     476        public Form MainForm { get; set; } 
    480477 
    481478        #region Events 
     
    547544        /// <param name="sender">The sender of the event.</param> 
    548545        private void OnExitInstance(object sender) 
     546        { 
     547            if (ExitInstance != null) 
     548                ExitInstance(sender); 
     549        } 
     550 
     551        /// <summary> 
     552        /// Broadcasts the ExitInstance event after getting the FormClosed event from 
     553        /// the application's main form. 
     554        /// </summary> 
     555        /// <param name="sender">The sender of the event.</param> 
     556        private void OnExitInstance(object sender, FormClosedEventArgs e) 
    549557        { 
    550558            if (ExitInstance != null) 
Note: See TracChangeset for help on using the changeset viewer.