1 class Program2 {3 Private StaticMutex m;4 5 [STAThread]6 Static voidMain ()7 {8 BOOLCreateNew =false;9 Ten /* One * on servers running Terminal Services, named system mutexes can have two levels of visibility. A * If the name begins with the prefix "global\", the mutex is visible in all Terminal Server sessions. - * If the name begins with the prefix "local\", the mutex is only visible in the Terminal Server session in which it was created. In this case, you can have a separate mutex with the same name in each of the other Terminal server sessions on the server. - * If you do not specify a prefix when creating a named mutex, it takes the prefix "local\". the * In a Terminal Server session, only two mutexes with different name prefixes are separate mutexes, and these two mutexes are visible to all processes in a Terminal Server session. - * That is, the prefix name "global\" and "local\" describe the scope of the mutex name relative to the Terminal Server session (not the process). - */ - stringMutexname = String.Format ("global\\{0}","IPP PCL"); + - Try + { Am =NewSystem.Threading.Mutex (true, Mutexname, outcreateNew); at } - Catch(unauthorizedaccessexception unauthorizedaccessex) - { - //A named mutex exists and has access control security, but the user does not have mutexrights.fullcontrol. - } - in if(!CreateNew) - { toConsole.WriteLine ("application is running"); + - return; the } * $Console.WriteLine ("Success");Panax Notoginseng - Console.readkey (); the } +}
Only one instance of the application can be run on the same PC (considering multiple user sessions)