コード例 #1
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 <see cref="RunCallbacks"/> once this task has completed.
    /// </param>
    /// <returns>A task which represents the asynchronous operation.</returns>
    /// <remarks>
    /// <strong>Important:</strong> The completion callback is not executed automatically. Instead, 
    /// the callback is only executed when <see cref="RunCallbacks"/> is called. See 
    /// <see cref="RunCallbacks"/> for additional information.
    /// </remarks>
    /// <exception cref="ArgumentException">
    /// Invalid number of maximum threads set in <see cref="IWork.Options"/>.
    /// </exception>
    /// <exception cref="ArgumentNullException">
    /// <paramref name="action"/> is <see langword="null"/>.
    /// </exception>
    public static Task Start(Action action, WorkOptions options, Action completionCallback)
    {

      if (options.MaximumThreads < 1)
        throw new ArgumentException("options.MaximumThreads cannot be less than 1.", "options");

      var work = DelegateWork.Create();
      work.Action = action;
      work.Options = options;
      return Start(work, completionCallback);
#else
      throw new NotSupportedException("Unity builds do not yet support multithreading.");

    }
コード例 #2
0
    /// <summary>
    /// Creates and 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 <see cref="RunCallbacks"/> once this task has completed.
    /// </param>
    /// <returns>A <see cref="Task{T}"/> which stores the result of the function.</returns>
    /// <remarks>
    /// <strong>Important:</strong> The completion callback is not executed automatically. Instead, 
    /// the callback is only executed when <see cref="RunCallbacks"/> is called. See 
    /// <see cref="RunCallbacks"/> for additional information.
    /// </remarks>
    /// <exception cref="ArgumentNullException">
    /// <paramref name="function"/> is <see langword="null"/>.
    /// </exception>
    /// <exception cref="ArgumentException">
    /// Invalid number of maximum threads set in <see cref="IWork.Options"/>.
    /// </exception>
    public static Task<T> Start<T>(Func<T> function, WorkOptions options, Action completionCallback)
    {

      if (options.MaximumThreads < 1)
        throw new ArgumentException("options.MaximumThreads cannot be less than 1.", "options");

      var work = FutureWork<T>.Create();
      work.Function = function;
      work.Options = options;
      var task = Start(work, completionCallback);
      return new Task<T>(task, work);
#else
      throw new NotSupportedException("Unity builds do not yet support multithreading.");

    }
コード例 #3
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 <see cref="Task{T}"/> which stores the result of the function.</returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="function"/> is <see langword="null"/>.
 /// </exception>
 public static Task<T> Start<T>(Func<T> function, WorkOptions options)
 {
   return Start(function, options, null);
 }
コード例 #4
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 the asynchronous operation.</returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="action"/> is <see langword="null"/>.
 /// </exception>
 public static Task Start(Action action, WorkOptions options)
 {
   return Start(action, options, null);
 }
コード例 #5
0
 private ForLoopWork()
 {
   Options = new WorkOptions { MaximumThreads = int.MaxValue };
 }