How to call win32 CreateMutex from .Net

后端 未结 3 2028
执念已碎
执念已碎 2020-12-20 09:33

I\'ve been successfully creating a .net mutex like this: SingleIns = new Mutex(true, AppName); for a while. It works in XP, Vista, but apparently not in Windows7. So I nee

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-20 10:18

    Should be as simple as:

    private static System.Threading.Mutex _mutex = null;
    
    const string guid = "{...GUID...}";
    bool createdNew;
    
    _mutex = new Mutex(true, guid, out createdNew);
    
    if (!createdNew) {
        // it is in use already
    }
    

    system wide mutex creation - ownership: https://stackoverflow.com/a/3111740/1644202

提交回复
热议问题