Changeset 2661


Ignore:
Timestamp:
5/24/2012 5:25:09 AM (3 years ago)
Author:
lowjoel
Message:

Handle the situation where creating a new mutex when starting the application would cause an UnauthorizedAccessException?. I can't figure out when this can happen since our mutex name contains the windows SID of the user launching it, but we'll have to live with it for now.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser/Program.GuiProgram.cs

    r2538 r2661  
    5757 
    5858                //Check if there already is another instance of the program. 
    59                 bool isFirstInstance = false; 
    60                 GlobalMutex = new Mutex(true, instanceID, out isFirstInstance); 
    61                 IsFirstInstance = isFirstInstance; 
     59                try 
     60                { 
     61                    bool isFirstInstance = false; 
     62                    GlobalMutex = new Mutex(true, instanceID, out isFirstInstance); 
     63                    IsFirstInstance = isFirstInstance; 
     64                } 
     65                catch (UnauthorizedAccessException) 
     66                { 
     67                    //If we get here, the mutex exists but we cannot modify it. That 
     68                    //would imply that this is not the first instance. 
     69                    //See http://msdn.microsoft.com/en-us/library/bwe34f1k.aspx 
     70                    IsFirstInstance = false; 
     71                } 
    6272            } 
    6373 
Note: See TracChangeset for help on using the changeset viewer.