/// <summary>Opens an existing named semaphore, specifying the desired security access rights.</summary> /// <returns>A <see cref="T:System.Threading.Semaphore" /> object that represents the named system semaphore.</returns> /// <param name="name">The name of a system semaphore.</param> /// <param name="rights">A bitwise combination of the <see cref="T:System.Security.AccessControl.SemaphoreRights" /> values that represent the desired security access rights.</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="name" /> is an empty string.-or-<paramref name="name" /> is longer than 260 characters.</exception> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="name" /> is null.</exception> /// <exception cref="T:System.Threading.WaitHandleCannotBeOpenedException">The named semaphore does not exist.</exception> /// <exception cref="T:System.IO.IOException">A Win32 error occurred.</exception> /// <exception cref="T:System.UnauthorizedAccessException">The named semaphore exists, but the user does not have the desired security access rights.</exception> /// <filterpriority>1</filterpriority> public static Semaphore OpenExisting(string name, System.Security.AccessControl.SemaphoreRights rights) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0 || name.Length > 260) { throw new ArgumentException("name", Locale.GetText("Invalid length [1-260].")); } MonoIOError monoIOError; IntPtr intPtr = Semaphore.OpenSemaphore_internal(name, rights, out monoIOError); if (!(intPtr == (IntPtr)null)) { return(new Semaphore(intPtr)); } if (monoIOError == MonoIOError.ERROR_FILE_NOT_FOUND) { throw new WaitHandleCannotBeOpenedException(Locale.GetText("Named Semaphore handle does not exist: ") + name); } if (monoIOError == MonoIOError.ERROR_ACCESS_DENIED) { throw new UnauthorizedAccessException(); } throw new IOException(Locale.GetText("Win32 IO error: ") + monoIOError.ToString()); }
private static extern IntPtr OpenSemaphore_internal(string name, System.Security.AccessControl.SemaphoreRights rights, out MonoIOError error);