示例#1
0
 /// <summary>
 /// Vytvoří vlákno s danou funkcí a spustí ho
 /// </summary>
 /// <param name="i">Parametr, který se předá funkci</param>
 /// <param name="action"></param>
 private static void StartThread(int i, Action<int> action, Object lockDecrement, ParallelStatus status)
 {
     Thread thread = new Thread(() => {
         action(i);
         lock(lockDecrement)
         {
             status.NumbersRunningThreads--;
         }
     });
     thread.IsBackground = true;
     thread.Priority = ThreadPriority.BelowNormal;
     thread.Start();
 }
示例#2
0
        /// <summary>
        /// Paralelní for
        /// </summary>
        /// <param name="repeat">Počet opakování</param>
        /// <param name="action">Funkce, která má běžet ve vláknu</param>
        public static void For(int repeat, Action<int> action)
        {
            Object lockDecrement = new object();
            ParallelStatus status = new ParallelStatus(repeat);

            for (int i = 0; i < repeat; i++)
                StartThread(i, action, lockDecrement, status);

            while (status.Alive)
            {
                Thread.Sleep(10);
            }
        }