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 badProducer = new BadPointsProducer(loggerService); var randomProducer = new RandomPointProducer(loggerService); var client = new Client(); badProducer.onBadPointProduced += client.onPointReceive; badProducer.OnEqualZero += client.onPointReceive; badProducer.OnMoreTenYProduced += client.onPointReceive; var pointProducers = new List <IPointProducer>() { quadraticProducer /*, cubicProducer, squareProducer,*/, badProducer }; Console.WriteLine("Press Enter for escape log"); System.Threading.Thread.Sleep(2000); Registry registry = new Registry(pointProducers); new Logic().Run(registry); var sinCurveProducer = new SinCurvePointsProducer(loggerService); var disposePointProducers = new List <SinCurvePointsProducer>() { sinCurveProducer }; RegistryWithDispose disposeRegistry = new RegistryWithDispose(disposePointProducers); new Logic().RunWithDispose(disposeRegistry); 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(); }
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(); }