static void Main(string[] args) { XmlConfigurator.Configure(); var logger = LogManager.GetLogger("SampleTextLogger"); var loggerService = new LoggerService(logger); var quadraticProducer = new CustomPointsProducer(x => x * x, -3, 1); var scalingProducer = new CustomPointsProducer(x => x * 2, -3, 1); var cubicBadProducer = new BadPointsProducer(loggerService, x => x * x * x, -3, (decimal)0.5, x => x % 2 == 0); ProducerCancelingManager manager = new ProducerCancelingManager(); manager.Add(quadraticProducer, 'q'); manager.Add(scalingProducer, 'w'); manager.Add(cubicBadProducer, 'e'); Client client = new Client("BadProducerSubscriber"); client.StartListenToBadProducer(cubicBadProducer); Task.Run(() => { quadraticProducer.Run((point) => loggerService.Info($"Quadratic Function {point}")); }); Task.Run(() => { scalingProducer.Run((point) => loggerService.Info($"Scaling Function {point}")); }); Task.Run(() => { cubicBadProducer.Run((point) => loggerService.Info($"Cubic Function {point}")); }); ConsoleKeyInfo key = new ConsoleKeyInfo(); while (key.Key != ConsoleKey.Escape) { key = Console.ReadKey(true); manager.CancelProducer(key); } }
static void Main(string[] args) { XmlConfigurator.Configure(); var logger = LogManager.GetLogger("SampleTextLogger"); var loggerService = new LoggerService(logger); var quadraticProducer = new QuadraticCurvePointsProducer(loggerService); var cubicProducer = new CubicCurvePointsProducer(loggerService); var squareProducer = new SquareCurvePointsProducer(loggerService); var bomb = new Bomb(loggerService); quadraticProducer.OnZeroXProduced += bomb.Fire; cubicProducer.OnZeroXProduced += bomb.Fire; bomb.Producers.Add(quadraticProducer); Task.Run(() => { quadraticProducer.Run((point) => loggerService.Info($"Quadratic Function {point}")); }); Task.Run(() => { cubicProducer.Run((point) => loggerService.Info($"Cubic Function {point}")); }); Task.Run(() => { squareProducer.Run((point) => loggerService.Info($"Square Function {point}")); }); System.Threading.Thread.Sleep(5000); quadraticProducer.IsContinue = false; System.Threading.Thread.Sleep(5000); cubicProducer.IsContinue = false; System.Threading.Thread.Sleep(5000); squareProducer.IsContinue = false; System.Threading.Thread.Sleep(2000); loggerService.Info("Remove pointers to producers"); quadraticProducer = null; cubicProducer = null; squareProducer = null; loggerService.Info("Run a IDisposable object..."); Task.Run(() => { using (var sinCuvrePointsProducer = new SinCurvePointsProducer(loggerService)) { Task.Run(() => { sinCuvrePointsProducer.Run((point) => loggerService.Info($"Sin Function {point}")); }); System.Threading.Thread.Sleep(5000);; sinCuvrePointsProducer.IsContinue = false; } }); Console.WriteLine("Press enter to run GC, step 1:"); Console.ReadLine(); GC.Collect(); Console.WriteLine("Press enter to run GC, step 1:done"); Console.ReadLine(); }