示例#1
0
 private static void InvokeSchedulable(IAsyncOperation op, IAsyncSchedulable s)
 {
     if (op.IsCompletedSuccessfully)
     {
         s.Start();
     }
     else
     {
         s.Cancel();
     }
 }
        /// <summary>
        /// Schedules a <paramref name="continuation"/> to be started (or cancelled in case of the operatino failure) after the operation has completed.
        /// If the operation is completed <paramref name="continuation"/> is invoked on the <paramref name="syncContext"/> specified.
        /// </summary>
        /// <remarks>
        /// The <paramref name="continuation"/> is invoked on a <see cref="SynchronizationContext"/> specified. Throwing an exception from the callback might cause unspecified behaviour.
        /// </remarks>
        /// <param name="continuation">The continuation to be executed when the operation has completed.</param>
        /// <param name="syncContext">If not <see langword="null"/> method attempts to marshal the continuation to the synchronization context.
        /// Otherwise the callback is invoked on a thread that initiated the operation completion.
        /// </param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="continuation"/> is <see langword="null"/>.</exception>
        /// <exception cref="ObjectDisposedException">Thrown is the operation has been disposed.</exception>
        public void Schedule(IAsyncSchedulable continuation, SynchronizationContext syncContext)
        {
            ThrowIfDisposed();

            if (continuation == null)
            {
                throw new ArgumentNullException(nameof(continuation));
            }

            if (!TryAddCallback(continuation, syncContext, true))
            {
                InvokeCompletionCallback(continuation, syncContext);
            }
        }
 /// <summary>
 /// Schedules a <paramref name="continuation"/> to be started (or cancelled in case of the operatino failure) after the operation has completed.
 /// If the operation is already completed the <paramref name="continuation"/> is called synchronously.
 /// </summary>
 /// <remarks>
 /// The <paramref name="continuation"/> is invoked on a thread that registered the continuation (if it has a <see cref="SynchronizationContext"/> attached).
 /// Throwing an exception from the callback might cause unspecified behaviour.
 /// </remarks>
 /// <param name="continuation">The continuation to be executed when the operation has completed.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="continuation"/> is <see langword="null"/>.</exception>
 /// <exception cref="ObjectDisposedException">Thrown is the operation has been disposed.</exception>
 public void Schedule(IAsyncSchedulable continuation)
 {
     Schedule(continuation, SynchronizationContext.Current);
 }
示例#4
0
 /// <summary>
 /// Schedules a continuation to run after the lazy operation succeeds.
 /// </summary>
 /// <param name="continuation">A continuation to schedule after this operation completes.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="continuation"/> value is <see langword="null"/>.</exception>
 /// <exception cref="InvalidOperationException">Thrown if <see cref="OperationFactory"/> is <see langword="null"/>.</exception>
 public void Schedule(IAsyncSchedulable continuation)
 {
     StartOrUpdate().Schedule(continuation);
 }