Esempio n. 1
0
        /// <summary>
        /// Tries to open an existing semaphore.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="namedEvent"></param>
        /// <returns></returns>
        public static new bool TryOpenExisting(string name, out NamedEvent namedEvent)
        {
            var semaphore = new NamedSemaphore(name, Native.OpenFlags.O_RDWR);

            if (semaphore.semaphoreHandle.IsInvalid)
            {
                namedEvent = null;
                return(false);
            }

            namedEvent = semaphore;
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates or opens a named semaphore.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static new NamedSemaphore CreateOrOpen(string name)
        {
            var namedSemaphore = new NamedSemaphore(name, Native.OpenFlags.O_CREAT);

            if (namedSemaphore.semaphoreHandle.IsInvalid)
            {
                throw new IOException(
                          $"Failed to create a NamedSemaphore {name}",
                          innerException: new Win32Exception(Marshal.GetLastWin32Error()));
            }

            return(namedSemaphore);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates or opens a named semaphore.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static new NamedSemaphore CreateOrOpen(string name)
        {
            var namedSemaphore = new NamedSemaphore(name, Native.OpenFlags.O_CREAT);

            return(namedSemaphore);
        }