Esempio n. 1
0
        public ProducerWorker(string name, ConsumerWorkerController <T> controller, Context ctx, CultureInfo culture)
        {
            this.Ctx        = ctx;
            this.Controller = controller;
            //this.Name = name;
            //this.CommitLogToDBWhenEnded = true;

            worker                = new Thread(ProducerStart);
            worker.Name           = name;
            worker.CurrentCulture = culture;
            worker.Start(Ctx);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            Context ctx = new Context();

            //using(ConsumerWorkerController<Book> conumsers = new ConsumerWorkerController<Book>(
            using (ConsumerWorkerController <Book> ctrl = new ConsumerWorkerController <Book>(3, 2, ctx))
            {
                //ctrl.InitializeWorkers<Book>();
                ctrl.CreateConsumerWorker += new ConsumerWorkerController <Book> .CreateConsumerWorkerEvent(ctrl_CreateWorker);

                ctrl.CreateProducerWorker += new ConsumerWorkerController <Book> .CreateProducerWorkerEvent(ctrl_CreateProducerWorker);

                ctrl.Initialize();

                //for (int i = 0; i < 5; i++)
                //{
                //    ctrl.Workers[i] = new TestConsumer1(i.ToString(), ctrl);
                //}
                //TaskQueue<Book> queue = new TaskQueue<Book>();
                //ctrl.que
                //for (int i = 0; i < 10; i++)
                //{
                //    Book b = new Book(i);
                //    Thread.Sleep(250);
                //    ctrl.PushProduct(b);
                //    //b.Consume();
                //}
            }

            //using (TaskQueue<Book> queue = new TaskQueue<Book>(5))
            //{
            //    for (int i = 0; i < 10; i++)
            //    {
            //        Book b = new Book(i);
            //        //Thread.Sleep(2500);
            //        queue.EnqueueTask(b);
            //        //b.Consume();
            //    }
            //}

            sw.Stop();
            Console.WriteLine("Last Seconds: " + sw.Elapsed.TotalSeconds);
            Console.Read();
        }
Esempio n. 3
0
 static ConsumerWorker <Book> ctrl_CreateWorker(ConsumerWorkerController <Book> workerController, string workerName, Context ctx)
 {
     return(new TestConsumer1(workerName, workerController, ctx, System.Globalization.CultureInfo.CurrentCulture));
 }
Esempio n. 4
0
 //public int Index { get; private set; }
 public TestProducer1(string name, ConsumerWorkerController <Book> ctrl, Context ctx, CultureInfo culture)
     : base(name, ctrl, ctx, culture)
 {
     //this.Name = name;
 }