Esempio n. 1
0
 public ThreadWorker(ThreadQueue <string> queue, int index)
 {
     this.queue = queue;
     this.index = index;
     Thrd       = new Thread(this.Run);
     Thrd.Start();
 }
Esempio n. 2
0
        public TestThreadQueue(int count)
        {
            ThreadQueue <string> queue   = new ThreadQueue <string>();
            List <ThreadWorker>  threads = new List <ThreadWorker>();

            for (int i = 1; i <= count; i++)
            {
                threads.Add(new ThreadWorker(queue, i));
            }

            while (Console.KeyAvailable == false)
            {
                foreach (ThreadWorker thread in threads)
                {
                    thread.Push();
                    Thread.Sleep(500);
                }
            }

            foreach (ThreadWorker thread in threads)
            {
                thread.Active = false;
            }
        }