/// <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="staticWorkloadExecutorIndexed">A (static) method that computes one workLoad-object at a time and provides the index of the array it origionally came from</param> /// <param name="workLoad">An array with objects you want to get computed by the executor</param> public ThreadWorkDistribution(ThreadWorkloadExecutorIndexed <T> workloadExecutorIndexed, T[] workLoad, int startIndex, int endIndex) { this.workloadExecutorIndexed = workloadExecutorIndexed; this.workLoad = workLoad; this.startIndex = startIndex; this.endIndex = endIndex; }
/// <summary> /// Helps spreading the same repetetive workload over multiple threads/cores in an easy way. /// Besides the workLoad-object, the current index of the workLoad-array is passed to the Executor-delegate. /// </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>(ThreadWorkloadExecutorIndexed <T> workloadExecutor, T[] workLoad, MultithreadedWorkloadComplete <T> onComplete, MultithreadedWorkloadPackageComplete <T> onPackageComplete, int maxThreads = -1, ThreadPoolScheduler scheduler = null, bool safeMode = true) { return(MultithreadedWorkloadHelper.StartMultithreadedWorkloadExecution <ThreadWorkloadExecutorIndexed <T>, T>(workloadExecutor, workLoad, null, onComplete, onPackageComplete, maxThreads, scheduler, safeMode)); }