/// <summary>
        /// Attempts to transition the underlying
        /// <see cref="T:System.Threading.Tasks.Task{TResult}"/> into the
        /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>
        /// state.
        /// </summary>
        /// <param name="result">The result value to bind to this <see
        /// cref="T:System.Threading.Tasks.Task{TResult}"/>.</param>
        /// <returns>True if the operation was successful; otherwise, false.</returns>
        /// <remarks>This operation will return false if the
        /// <see cref="T:System.Threading.Tasks.Task{TResult}"/> is already in one
        /// of the three final states:
        /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
        /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
        /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
        /// </remarks>
        /// <exception cref="T:System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
        public bool TrySetResult(TResult result)
        {
            bool rval = m_task.TrySetResult(result);

            if (!rval && !m_task.IsCompleted)
            {
                m_task.Wait();
            }
            return(rval);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Attempts to transition the underlying
 /// <see cref="T:System.Threading.Tasks.Task{TResult}"/> into the
 /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>
 /// state.
 /// </summary>
 /// <param name="result">The result value to bind to this <see
 /// cref="T:System.Threading.Tasks.Task{TResult}"/>.</param>
 /// <returns>True if the operation was successful; otherwise, false.</returns>
 /// <remarks>This operation will return false if the
 /// <see cref="T:System.Threading.Tasks.Task{TResult}"/> is already in one
 /// of the three final states:
 /// <see cref="System.Threading.Tasks.TaskStatus.RanToCompletion">RanToCompletion</see>,
 /// <see cref="System.Threading.Tasks.TaskStatus.Faulted">Faulted</see>, or
 /// <see cref="System.Threading.Tasks.TaskStatus.Canceled">Canceled</see>.
 /// </remarks>
 /// <exception cref="T:System.ObjectDisposedException">The <see cref="Task"/> was disposed.</exception>
 public bool TrySetResult(TResult result)
 {
     return(m_task.TrySetResult(result));
 }