Exemplo n.º 1
0
 public ForLoopWork()
 {
     Options = new WorkOptions()
     {
         MaximumThreads = int.MaxValue
     };
 }
Exemplo n.º 2
0
 public ForEachLoopWork()
 {
     Options = new WorkOptions()
     {
         MaximumThreads = int.MaxValue
     };
     syncLock = new object();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates and starts a task to execute the given work.
        /// </summary>
        /// <param name="action">The work to execute in parallel.</param>
        /// <param name="options">The work options to use with this action.</param>
        /// <param name="completionCallback">A method which will be called in Parallel.RunCallbacks() once this task has completed.</param>
        /// <returns>A task which represents one execution of the work.</returns>
        public static Task Start(Action action, WorkOptions options, Action completionCallback)
        {
            if (options.MaximumThreads < 1)
            {
                throw new ArgumentOutOfRangeException("options", "options.MaximumThreads cannot be less than 1.");
            }
            var work = DelegateWork.GetInstance();

            work.Action  = action;
            work.Options = options;
            return(Start(work, completionCallback));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates an starts a task which executes the given function and stores the result for later retrieval.
        /// </summary>
        /// <typeparam name="T">The type of result the function returns.</typeparam>
        /// <param name="function">The function to execute in parallel.</param>
        /// <param name="options">The work options to use with this action.</param>
        /// <param name="completionCallback">A method which will be called in Parallel.RunCallbacks() once this task has completed.</param>
        /// <returns>A future which represents one execution of the function.</returns>
        public static Future <T> Start <T>(Func <T> function, WorkOptions options, Action completionCallback)
        {
            if (options.MaximumThreads < 1)
            {
                throw new ArgumentOutOfRangeException("options", "options.MaximumThreads cannot be less than 1.");
            }
            var work = FutureWork <T> .GetInstance();

            work.Function = function;
            work.Options  = options;
            var task = Start(work, completionCallback);

            return(new Future <T>(task, work));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates an starts a task which executes the given function and stores the result for later retrieval.
 /// </summary>
 /// <typeparam name="T">The type of result the function returns.</typeparam>
 /// <param name="function">The function to execute in parallel.</param>
 /// <param name="options">The work options to use with this action.</param>
 /// <returns>A future which represents one execution of the function.</returns>
 public static Future <T> Start <T>(Func <T> function, WorkOptions options)
 {
     return(Start <T>(function, options, null));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates and starts a task to execute the given work.
 /// </summary>
 /// <param name="action">The work to execute in parallel.</param>
 /// <param name="options">The work options to use with this action.</param>
 /// <returns>A task which represents one execution of the work.</returns>
 public static Task Start(Action action, WorkOptions options)
 {
     return(Start(action, options, null));
 }