16 lines
398 B
C#
16 lines
398 B
C#
namespace Dlhis.Basic;
|
|
|
|
public static class ParallelExtensions
|
|
{
|
|
public static void ParallelForEach<T>(this IEnumerable<T> source, Action<T> action)
|
|
{
|
|
#if DEBUG
|
|
foreach (var item in source)
|
|
{
|
|
action.Invoke(item);
|
|
}
|
|
#else
|
|
Parallel.ForEach(source, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, action);
|
|
#endif
|
|
}
|
|
} |