コード例 #1
0
        /// <summary>
        /// Attaches a <see cref="Condition" /> to the <see cref="WaitSet" />.
        /// </summary>
        /// <remarks>
        /// <para>It is possible to attach a <see cref="Condition" /> on a <see cref="WaitSet" /> that is currently being waited upon (via the wait operation). In this case, if the
        /// <see cref="Condition" /> has a <see cref="Condition.TriggerValue" /> of <see langword="true"/>, then attaching the condition will unblock the <see cref="WaitSet" />.</para>
        /// <para>Adding a <see cref="Condition" /> that is already attached to the <see cref="WaitSet" /> has no effect.</para>
        /// </remarks>
        /// <param name="cond">The <see cref="Condition" /> to be attached.</param>
        /// <returns>The <see cref="ReturnCode" /> that indicates the operation result.</returns>
        public ReturnCode AttachCondition(Condition cond)
        {
            if (cond == null)
            {
                return(ReturnCode.BadParameter);
            }

            ReturnCode ret = UnsafeNativeMethods.AttachCondition(_native, cond.ToNative());

            if (ret == ReturnCode.Ok)
            {
                _conditions.AddOrUpdate(cond.ToNative(), cond, (p, t) => cond);
            }

            return(ret);
        }