Exemplo n.º 1
0
 /// <summary>
 /// ThreadWorkDistribion is a workload-packages containing a subdived segment of work based on the workload divided by the amount of packages
 /// </summary>
 /// <param name="staticWorkloadExecutor">A (static) method that computes one workLoad-object at a time</param>
 /// <param name="workLoad">An array with objects you want to get computed by the executor</param>
 public ThreadWorkDistribution(ThreadWorkloadExecutor <T> workloadExecutor, T[] workLoad, int startIndex, int endIndex)
 {
     this.workloadExecutor = workloadExecutor;
     this.workLoad         = workLoad;
     this.startIndex       = startIndex;
     this.endIndex         = endIndex;
 }
Exemplo n.º 2
0
    //--------------------------------------- 2 START SINGLE THREAD OVERLOADS --------------------------------------
    //--------------------------------------- 2 START SINGLE THREAD OVERLOADS --------------------------------------



    //--------------------------------------- 4 MULTI THREADED WORK EXECUTION OVERLOADS --------------------------------------
    //--------------------------------------- 4 MULTI THREADED WORK EXECUTION OVERLOADS --------------------------------------

    #region 4 MULTI THREADED WORK EXECUTION OVERLOADS
    /// <summary>
    /// Helps spreading the same repetetive workload over multiple threads/cores in an easy way.
    /// </summary>
    /// <typeparam name="T">T: Generic-Type of the object you want to be computed by the executor</typeparam>
    /// <param name="staticWorkloadExecutor"> A (static) method that computes one workLoad-object at a time</param>
    /// <param name="workLoad">An array with objects you want to get computed by the executor</param>
    /// <param name="onComplete">Fired when all re-packaged workLoad-objects are finished computing</param>
    /// <param name="onPackageExecuted">Fires foreach finished re-packaged set of workLoad-object</param>
    /// <param name="maxThreads"> Lets you choose how many threads will be run simultaneously by the threadpool. Default: -1 == number of cores minus one, to make sure the MainThread has at least one Core to run on. (quadcore == 1 Core Mainthread, 3 cores used by the ThreadPoolScheduler)</param>
    /// <param name="scheduler">If Null, a new ThreadPoolScheduler will be instantiated.</param>
    /// <param name="safeMode">Executes all the computations within try-catch events, logging it the message + stacktrace</param>
    /// <returns>A ThreadPoolScheduler that handles all the repackaged workLoad-Objects</returns>
    public static ThreadPoolScheduler StartMultithreadedWorkloadExecution <T>(ThreadWorkloadExecutor <T> workloadExecutor, T[] workLoad, MultithreadedWorkloadComplete <T> onComplete, MultithreadedWorkloadPackageComplete <T> onPackageComplete, int maxThreads = -1, ThreadPoolScheduler scheduler = null, bool safeMode = true)
    {
        return(MultithreadedWorkloadHelper.StartMultithreadedWorkloadExecution <ThreadWorkloadExecutor <T>, T>(workloadExecutor, workLoad, null, onComplete, onPackageComplete, maxThreads, scheduler, safeMode));
    }