Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventWaitHandleLocker"/> class using a
        /// co-initialized instance of the <see cref="EventWaitHandle"/> class used as the
        /// wait handle, specifying whether the wait handle is initially signaled if created
        /// as a result of this call, whether it resets automatically or manually, the name
        /// of a system synchronization event, and a Boolean variable whose value after the
        /// call indicates whether the named system event was created.
        /// </summary>
        /// <param name="initialState">Specify <c>true</c> to set the initial state to signaled
        /// if the named event is created as a result of this call; <c>false</c> to set it to
        /// nonsignaled.</param>
        /// <param name="mode">One of the <see cref="EventResetMode"/> values
        /// that determines whether the event resets automatically or manually.</param>
        /// <param name="name">The name of a system-wide synchronization event.</param>
        /// <returns></returns>
        public static EventWaitHandleLocker MakeWithEventHandle(bool initialState,
                                                                EventResetMode mode,
                                                                string name)
        {
            var eventWaitHandle = new EventWaitHandle(initialState, mode, name);
            var instance        = new EventWaitHandleLocker(eventWaitHandle, mode == EventResetMode.AutoReset);

            return(instance);
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventWaitHandleLocker"/> class using a
        /// co-initialized instance of the <see cref="EventWaitHandle"/> class used as the
        /// wait handle, specifying whether the wait handle is initially signaled if created
        /// as a result of this call, whether it resets automatically or manually, the name
        /// of a system synchronization event, and a Boolean variable whose value after the
        /// call indicates whether the named system event was created.
        /// </summary>
        /// <param name="initialState">Specify <c>true</c> to set the initial state to signaled
        /// if the named event is created as a result of this call; <c>false</c> to set it to
        /// nonsignaled.</param>
        /// <param name="mode">One of the <see cref="EventResetMode"/> values
        /// that determines whether the event resets automatically or manually.</param>
        /// <param name="name">The name of a system-wide synchronization event.</param>
        /// <param name="createdNew">When this method returns, contains true if a local event
        /// was created (that is, if name is null or an empty string) or if the specified named
        /// system event was created; false if the specified named system event already existed.
        /// This parameter is passed uninitialized.</param>
        /// <returns></returns>
        public static EventWaitHandleLocker MakeWithEventHandle(bool initialState,
                                                                EventResetMode mode,
                                                                string name,
                                                                out bool createdNew,
                                                                TimeSpan timeout)
        {
            if (timeout < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("timeout",
                                                      timeout,
                                                      "Timeout is a negative number other than -1 milliseconds, which represents an infinite time-out.-or-timeout is greater than System.Int32.MaxValue.");
            }

            var eventWaitHandle = new EventWaitHandle(initialState, mode, name, out createdNew);
            var instance        = new EventWaitHandleLocker(eventWaitHandle, timeout, mode == EventResetMode.AutoReset);

            return(instance);
        }