Пример #1
0
        public Worker(SenderDispatch dispatcher, string workerName)
        {
            this.dispatcher = dispatcher;
            this.workerName = workerName;

            this.working = false;
        }
Пример #2
0
        static void Main()
        {
            SenderDispatch dispatch = new SenderDispatch();

            List <Worker> workers = new List <Worker>();

            workers.Add(new Worker(dispatch, "A"));
            workers.Add(new Worker(dispatch, "B"));
            workers.Add(new Worker(dispatch, "C"));
            workers.Add(new Worker(dispatch, "D"));

            Thread.CurrentThread.Name = "Main thread";
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;

            Stopwatch watch = new Stopwatch();

            watch.Start();
            workers.ForEach(x => x.Start());

            for (int i = 0; i < 20; i++)
            {
                Thread.Sleep(10000);
                dispatch.NewSender();
            }

            Console.WriteLine("Stopping...");

            workers.ForEach(x => x.Stop());
            watch.Stop();

            Console.WriteLine("Stopped");

            long sum = workers.Sum(x => x.FinalCount);

            string message =
                "Sum of worker iterations: " + sum.ToString("n0") + "\r\n" +
                "Total time:               " + (watch.ElapsedMilliseconds / 1000.0).ToString("0.000") + "\r\n" +
                "Iterations/ms:            " + sum / watch.ElapsedMilliseconds;

            MessageBox.Show(message);
        }