示例#1
0
 public Semaphore(int initialCount, int maximumCount, string name, out bool createdNew, System.Security.AccessControl.SemaphoreSecurity semaphoreSecurity)
 {
     if (initialCount < 0)
     {
         throw new ArgumentOutOfRangeException("initialCount", "< 0");
     }
     if (maximumCount < 1)
     {
         throw new ArgumentOutOfRangeException("maximumCount", "< 1");
     }
     if (initialCount > maximumCount)
     {
         throw new ArgumentException("initialCount > maximumCount");
     }
     this.Handle = Semaphore.CreateSemaphore_internal(initialCount, maximumCount, name, out createdNew);
 }
示例#2
0
        /// <summary>Initializes a new instance of the <see cref="T:System.Threading.Semaphore" /> class, specifying the maximum number of concurrent entries, optionally reserving some entries for the calling thread, and optionally specifying the name of a system semaphore object.</summary>
        /// <param name="initialCount">The initial number of requests for the semaphore that can be granted concurrently. </param>
        /// <param name="maximumCount">The maximum number of requests for the semaphore that can be granted concurrently.</param>
        /// <param name="name">The name of a named system semaphore object.</param>
        /// <exception cref="T:System.ArgumentException">
        ///   <paramref name="initialCount" /> is greater than <paramref name="maximumCount" />.-or-<paramref name="name" /> is longer than 260 characters.</exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///   <paramref name="maximumCount" /> is less than 1.-or-<paramref name="initialCount" /> is less than 0.</exception>
        /// <exception cref="T:System.IO.IOException">A Win32 error occurred.</exception>
        /// <exception cref="T:System.UnauthorizedAccessException">The named semaphore exists and has access control security, and the user does not have <see cref="F:System.Security.AccessControl.SemaphoreRights.FullControl" />.</exception>
        /// <exception cref="T:System.Threading.WaitHandleCannotBeOpenedException">The named semaphore cannot be created, perhaps because a wait handle of a different type has the same name.</exception>
        public Semaphore(int initialCount, int maximumCount, string name)
        {
            if (initialCount < 0)
            {
                throw new ArgumentOutOfRangeException("initialCount", "< 0");
            }
            if (maximumCount < 1)
            {
                throw new ArgumentOutOfRangeException("maximumCount", "< 1");
            }
            if (initialCount > maximumCount)
            {
                throw new ArgumentException("initialCount > maximumCount");
            }
            bool flag;

            this.Handle = Semaphore.CreateSemaphore_internal(initialCount, maximumCount, name, out flag);
        }