private void InternalCreateMutex(bool bInitialOwner, string strName) { try { lock (padlock) { InternalMutexName = strName; SECURITY_DESC sd; SECURITY_ATT sa = new SECURITY_ATT(); SecurityDescriptor.GetNullDaclSecurityDescriptor(out sd); sa.lpSecurityDescriptor = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SECURITY_DESC))); Marshal.StructureToPtr(sd, sa.lpSecurityDescriptor, false); sa.bInheritHandle = false; sa.nLength = Marshal.SizeOf(typeof(SECURITY_ATT)); Handle = CreateMutexW(ref sa, bInitialOwner, InternalMutexName); if (Handle == InvalidHandle) { throw new Win32Exception(Marshal.GetLastWin32Error()); } //this.SafeWaitHandle = new Microsoft.Win32.SafeHandles.SafeWaitHandle(handle, true); } } catch { throw; } }
private static extern IntPtr CreateMutexW(ref SECURITY_ATT sd, bool bInitialOwner, string strName);