예제 #1
0
        /// <summary>
        /// Runs <paramref name="idleWork"/> over each item in <paramref name="workQueue"/> on the UI Thread during idle time.
        /// This method will keep iterating through <paramref name="workQueue"/> on the same idle loop while VS remains idle.
        /// Once VS is no longer idle, the method will yield control and pick up where it left off on the next idle loop.
        /// </summary>
        /// <typeparam name="T">The type of the data to be processed.</typeparam>
        /// <param name="this">The IVsTaskSchedulerService to use when scheduling the work.</param>
        /// <param name="idleWork">Action to run on idle.</param>
        /// <param name="workQueue">Data to process on idle.</param>
        /// <param name="token">Cancellation token to indicate when the work is no longer needed.</param>
        /// <returns
        /// >A task representing all of the asynchronous work this method is performing.  When the task is marked as completed,
        /// either all of the work in workQueue has been processed, or the operation was canceled.
        /// </returns>
        public static Task RunOnIdle <T>(this IVsTaskSchedulerService @this, Action <T> idleWork, ConcurrentQueue <T> workQueue, CancellationToken token)
        {
            // Check for good data
            if (idleWork == null)
            {
                throw new ArgumentNullException(nameof(idleWork));
            }

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

            return(@this.RunOnIdle(idleWork, workQueue.TryDequeue, token));
        }
예제 #2
0
        /// <summary>
        /// Runs <paramref name="idleWork"/> over each item in <paramref name="workData"/> on the UI Thread during idle time.
        /// This method will keep iterating through <paramref name="workData"/> on the same idle loop while VS remains idle.
        /// Once VS is no longer idle, the method will yield control and pick up where it left off on the next idle loop.
        /// </summary>
        /// <typeparam name="T">The type of the data to be processed.</typeparam>
        /// <param name="this">The IVsTaskSchedulerService to use when scheduling the work.</param>
        /// <param name="idleWork">Action to run on idle.</param>
        /// <param name="workData">Data to process on idle.</param>
        /// <param name="token">Cancellation token to indicate when the work is no longer needed.</param>
        /// <returns
        /// >A task representing all of the asynchronous work this method is performing.  When the task is marked as completed,
        /// either all of the work in workData has been processed, or the operation was canceled.
        /// </returns>
        public static Task RunOnIdle <T>(this IVsTaskSchedulerService @this, Action <T> idleWork, IEnumerable <T> workData, CancellationToken token)
        {
            // Check for good data
            if (idleWork == null)
            {
                throw new ArgumentNullException(nameof(idleWork));
            }

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

            // Make a copy of the items since we're going to be iterating over them across multiple dispatcher operations.
            T[] items   = workData.ToArray();
            var adapter = new TryGetNextItemEnumerableAdapter <T>(items);

            return(@this.RunOnIdle(idleWork, adapter.TryGetNextItem, token));
        }
예제 #3
0
 /// <summary>
 /// Runs <paramref name="idleWork"/> over each item in <paramref name="workData"/> on the UI Thread during idle time.
 /// This method will keep iterating through <paramref name="workData"/> on the same idle loop while VS remains idle.
 /// Once VS is no longer idle, the method will yield control and pick up where it left off on the next idle loop.
 /// </summary>
 /// <typeparam name="T">The type of the data to be processed.</typeparam>
 /// <param name="this">The IVsTaskSchedulerService to use when scheduling the work.</param>
 /// <param name="idleWork">Action to run on idle.</param>
 /// <param name="workData">Data to process on idle.</param>
 /// <returns
 /// >A task representing all of the asynchronous work this method is performing.  When the task is marked as completed,
 /// either all of the work in workData has been processed, or the operation was canceled.
 /// </returns>
 public static Task RunOnIdle <T>(this IVsTaskSchedulerService @this, Action <T> idleWork, IEnumerable <T> workData)
 {
     return(@this.RunOnIdle <T>(idleWork, workData, CancellationToken.None));
 }
예제 #4
0
 /// <summary>
 /// Runs <paramref name="idleWork"/> over each item returned from <paramref name="tryGetNextItem"/> on the UI Thread during idle time.
 /// This method will keep processing data from <paramref name="tryGetNextItem" /> on the same idle loop while VS remains idle.
 /// Once VS is no longer idle, the method will yield control and pick up where it left off on the next idle loop.
 /// </summary>
 /// <typeparam name="T">The type of the data to be processed.</typeparam>
 /// <param name="this">The IVsTaskSchedulerService to use when scheduling the work.</param>
 /// <param name="idleWork">Action to run on idle.</param>
 /// <param name="tryGetNextItem">Delegate used to get the next piece of data to process.  tryGetNextItem should return true
 /// when another item is available and false when there is no more data to process.</param>
 /// <returns>
 /// >A task representing all of the asynchronous work this method is performing.  When the task is marked as completed,
 /// either all of the work received from tryGetNextItem has been processed, or the operation was canceled.
 /// </returns>
 public static Task RunOnIdle <T>(this IVsTaskSchedulerService @this, Action <T> idleWork, TryGetNextItem <T> tryGetNextItem)
 {
     return(@this.RunOnIdle <T>(idleWork, tryGetNextItem, CancellationToken.None));
 }
예제 #5
0
 /// <summary>
 /// Runs <paramref name="idleWork"/> over each item in <paramref name="workQueue"/> on the UI Thread during idle time.
 /// This method will keep iterating through <paramref name="workQueue"/> on the same idle loop while VS remains idle.
 /// Once VS is no longer idle, the method will yield control and pick up where it left off on the next idle loop.
 /// </summary>
 /// <typeparam name="T">The type of the data to be processed.</typeparam>
 /// <param name="this">The IVsTaskSchedulerService to use when scheduling the work.</param>
 /// <param name="idleWork">Action to run on idle.</param>
 /// <param name="workQueue">Data to process on idle.</param>
 /// <returns
 /// >A task representing all of the asynchronous work this method is performing.  When the task is marked as completed,
 /// either all of the work in workQueue has been processed, or the operation was canceled.
 /// </returns>
 public static Task RunOnIdle <T>(this IVsTaskSchedulerService @this, Action <T> idleWork, ConcurrentQueue <T> workQueue)
 {
     return(@this.RunOnIdle <T>(idleWork, workQueue, CancellationToken.None));
 }