コード例 #1
0
        /// <summary>
        ///     Queues given <see cref="AsyncJob" /> for execution by <see cref="AsyncJobScheduler" />.
        /// </summary>
        /// <param name="asyncJob"><see cref="AsyncJob" /> to execute.</param>
        /// <remarks>
        ///     For performance reasons, the internal execution method utilizes ConfigureAwait(false).
        /// </remarks>
        public static void QueueAsyncJob(AsyncJob asyncJob)
        {
            if (AbortToken.IsCancellationRequested)
            {
                asyncJob.Cancel();
                return;
            }

            if (asyncJob.ExecutionState == AsyncJob.State.Cancelled)
            {
                throw new AsyncJobCancelledException("Cancelled jobs cannot be queued.", asyncJob);
            }

            OnJobQueued(asyncJob);

            Task executeJob = ExecuteJob(asyncJob);

            Task.Run(() => executeJob);

            if (executeJob.IsFaulted && executeJob.Exception is { })
コード例 #2
0
 /// <summary>
 ///     Instantiates a new <see cref="AsyncJobCancelledException" />.
 /// </summary>
 /// <param name="message">Message for the <see cref="Exception" />.</param>
 /// <param name="asyncJob">Subject <see cref="AsyncJob" /> of the <see cref="Exception" />.</param>
 public AsyncJobCancelledException(string message, AsyncJob asyncJob)
     : base(message) => AsyncJob = asyncJob;
コード例 #3
0
 /// <summary>
 ///     Instantiates a new <see cref="AsyncJobEventArgs" />.
 /// </summary>
 /// <param name="asyncJob">Subject <see cref="AsyncJob" /> of the event arguments.</param>
 public AsyncJobEventArgs(AsyncJob asyncJob) => AsyncJob = asyncJob;