예제 #1
0
        protected void ParallelWork(int n)
        {
            int i = 0;
            int m = (Count.HasValue ? Count.Value : Files.Length);
            ThreadStart work = () => {
                var p = new RagelParser();
                p.AddEvent((_) => { });
                while (i < m) {
                    Tuple<FileInfo, ArraySegment<byte>> tmp;
                    if (files.TryDequeue(out tmp)) {
                        ReadFile(p, tmp);
                        i++;
                    }
                }
            };

            Thread[] threads = new Thread[n];
            for (int j = 0; j < threads.Length; j++) {
                threads[j] = new Thread(work);
                threads[j].Start();
            }

            foreach (var thread in threads) {
                thread.Join();
            }
        }