AdvancedMultithreadingLab.MiscBenchmarks.RunParallel C# (CSharp) Метод

RunParallel() приватный статический Метод

private static RunParallel ( System.Action action, int threads ) : void
action System.Action
threads int
Результат void
        private static void RunParallel(Action action, int threads)
        {
            ManualResetEvent[] handles = new ManualResetEvent[threads];
            for ( int i = 0; i < threads; i++)
            {
                handles[i] = new ManualResetEvent( false );
                int i1 = i;
                Thread t1 = new Thread(() =>
                {
                    try
                    {
                        action();
                    }
                    finally
                {
                    handles[i1].Set();
                }});
                t1.Start();
            }
            WaitHandle.WaitAll( handles );
        }