示例#1
0
        public static void Main(string[] args)
        {
            MailManager manager = new MailManager();
            EventHandler <MailArrivedEventArgs> mailHandler = (sender, e) =>
            {
                Console.WriteLine("Mail title is {0} and mail body is {1}", e.Title, e.Body);
            };

            manager.MailArrived += mailHandler;
            manager.SimulateMailArrived("Hello", "Good day");
            // Check empty string
            manager.SimulateMailArrived("", "");
            // Check null
            manager.SimulateMailArrived(null, null);

            // Timer
            TimerCallback timerCallBack = (state) =>
            {
                manager.SimulateMailArrived("Notice", "Please dont forget your keys!");
            };
            Timer mailTimer = new Timer(timerCallBack, null, 0, 1000);

            Thread.Sleep(12000);
            manager.MailArrived -= mailHandler;
        }
 private void _callBack(object state)
 {
     if (state is MailManager && state != null)
     {
         MailManager tempMailManager = state as MailManager;
         tempMailManager.SimulateMailArrived();
     }
 }
        static void Main(string[] args)
        {
            MailManager mailManager = new MailManager();

            mailManager.MailArrived += mailManager.MailArrivedEvent;
            mailManager.SimulateMailArrived();
            Console.ReadLine();
        }
示例#4
0
        static void Main(string[] args)
        {
            MailManager manager = new MailManager();

            manager.MailArrived += manager_MailArrived;
            timer = new Timer(_ => manager.SimulateMailArrived(), null, 0, 1000);
            Console.ReadLine();
        }
示例#5
0
        public static void MailCallback(object args)
        {
            //No, you should have used the state argument or use some other way (like lambda's and capturing) for the mail.
            //This isn't what we wanted you to do.
            MailManager manager = new MailManager();

            manager.MailArrived += MailArrivedHandler;
            manager.SimulateMailArrived((MailArrivedEventArgs)args);
        }
示例#6
0
        static void Main(string[] args)
        {
            MailManager mailManager = new MailManager();

            mailManager.MailArrived += (obj, eventArgs) => Console.WriteLine(string.Format("The messege is: {0} {1}", eventArgs.Title, eventArgs.Body));
            mailManager.SimulateMailArrived();
            System.Threading.Timer timer = new System.Threading.Timer(o => mailManager.SimulateMailArrived(), null, 0, 1000);
            Console.ReadLine();
        }
示例#7
0
        static void Main(string[] args)
        {
            // creating and signing to MailManager and running timer that simulating messages that sent to the MailManager
            MailManager mgr = new MailManager();

            mgr.MailArrived += Mgr_MailArrived;
            Timer timer = new Timer(EventsSimulatorCallbck, mgr, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));

            Console.ReadKey();
        }
示例#8
0
        static void Main(string[] args)
        {
            MailManager mailManager = new MailManager();

            mailManager.MailArrived += Mm_MailArrived;
            mailManager.SimulateMailArrived();
            Timer timer = new Timer(new TimerCallback(TimerCallback), mailManager, 1000, 1000);

            Thread.Sleep(10000);
        }
示例#9
0
        static void Main(string[] args)
        {
            MailManager   mailManager = new MailManager();
            TimerCallback tcb         = new TimerCallback(mailManager.SimulateMailArrived);

            mailManager.MailArrived += MailManager_MailArrived;
            Timer timer = new Timer(tcb, null, 0, 1000);

            Console.ReadLine();
        }
示例#10
0
        static void Main(string[] args)
        {
            MailManager manager  = new MailManager();
            var         autoArgs = new MailArrivedEventArgs("this is a test", "test");

            manager.MailArrived += MailArrivedHandler;
            manager.SimulateMailArrived(autoArgs);
            Timer startTimer = new Timer(MailCallback, autoArgs, 1000, 1000);

            Console.ReadLine();
        }
示例#11
0
        static void Main(string[] args)
        {
            MailManager manager = new MailManager();

            manager.MailArrived += Manager_MailArrived;
            manager.SimulateMailArrived();

            System.Threading.Timer timer;
            timer = new System.Threading.Timer(new TimerCallback(manager.SimulateMailArrived), null, 0, 1000);
            Console.ReadLine();
        }
示例#12
0
        private static void TimerCallback(object state)
        {
            var mailData = new MailManager();//publisher

            mailData.MailArrived += (obj, mailevenArgs) => { Console.WriteLine(mailevenArgs.Title); };
            mailData.MailArrived += (obj, mailevenArgs) => { Console.WriteLine(mailevenArgs.Body); };

            mailData.SimulateMailArrived();

            Console.WriteLine($"{DateTime.Now.TimeOfDay}");
        }
示例#13
0
        public static void Main(string[] args)
        {
            var mailData = new MailManager();//publisher

            mailData.MailArrived += (obj, mailevenArgs) => { Console.WriteLine(mailevenArgs.Title); };
            mailData.MailArrived += (obj, mailevenArgs) => { Console.WriteLine(mailevenArgs.Body); };

            mailData.SimulateMailArrived();
            var timer = new Timer(TimerCallback, null, 1000, 1000);

            Console.ReadLine();
        }
示例#14
0
        public static void Main(string[] args)
        {
            _manager = new MailManager();
            var mailArgs = new MailArrivedEventArgs("Testing Mail Arrived Event", "TESTED");

            _manager.MailArrived += MailArrivedHandler;
            _manager.SimulateMailArrived(mailArgs);

            Timer timer = new Timer(Callback, mailArgs, 1000, 1000);

            Console.ReadLine();
        }
示例#15
0
        static void Main(string[] args)
        {
            MailManager manager = new MailManager();

            manager.MailArrived += Manager_MailArrived;
            manager.SimulateMailArrived(null);

            TimerCallback tcb   = manager.SimulateMailArrived;
            Timer         timer = new Timer(tcb, null, 1000, 1000);

            Thread.Sleep(10000);
        }
示例#16
0
        public static void Main(string[] args)
        {
            Program     program     = new Program();
            MailManager mailManager = new MailManager();

            mailManager.MailArrived += program.PrintMailDetails;

            Timer timer = new Timer((obj) =>
            {
                mailManager.SimulateMailArrived();
            }, null, 0, 1000);

            Console.ReadLine();
        }
示例#17
0
        static void Main(string[] args)
        {
            string title       = "Hello, it's me...";
            string body        = "I was wondering\nIf after all these years you'd like to meet to go over everything\nThey say that time's supposed to heal, yeah\nBut I ain't done much healing\n";
            var    mailManager = new MailManager();
            var    printMail   = new PrintMail();

            mailManager.MailArrived += printMail.OnMailArrived;

            var timer = new Timer((Object obj) => {
                mailManager.SimulateMailArrived(new MailArrivedEventArgs(title, body));
            }, null, 0, 1000);

            Console.ReadLine();
        }
示例#18
0
        public static void Main(string[] args)
        {
            MailManager          manager     = new MailManager();
            MailArrivedEventArgs mail        = new MailArrivedEventArgs("Nelly", "you got a new messege");
            MailArrivedEventArgs anotherMail = new MailArrivedEventArgs("Dror", "Mail");

            manager.MailArrived += GotMail;
            manager.SimulateMailArrived(new object());
            manager.MailSent(mail);
            manager.MailSent(anotherMail);

            TimerCallback timeCall = manager.SimulateMailArrived;

            System.Threading.Timer timer = new System.Threading.Timer(timeCall, null, 0, 1000);
            System.Threading.Thread.Sleep(10000);
        }
示例#19
0
        static void Main(string[] args)
        {
            // 7. In the Main method, create an instance of MailManager and connect to the MailArrived event.
            MailManager manager = new MailManager();

            // 9.Call the SimulateMailArrived to check the event connection.
            manager.SimulateMailArrived();

            //subscribe the handler to event
            manager.MailArrived += MailArrivedHandler;

            // 10. Create a System.Threading.Timer, and in the timer callback call SimulateMailArrived every 1 second.
            //     Call Thread.Sleep in the main thread to keep the application alive, or call Console.ReadLine.
            Timer timer = new Timer(_ => manager.SimulateMailArrived(), null, 0, 1000);

            Console.ReadLine();
        } /*** end main ***********************************/
示例#20
0
        static void Main(string[] args)
        {
            MailManager m = new MailManager();

            m.MailArrived += (s, e) =>
            {
                Console.WriteLine(e._title + " " + e._body);
            };
            m.MailArrived += m.PrintTwice;
            m.SimulateMailArrived();

            Timer timer = new Timer(delegate
            {
                m.SimulateMailArrived();
            }, null, 1000, 1000);

            Console.ReadKey();
        }
示例#21
0
        static void Main(string[] args)
        {
            MailManager mailManager = new MailManager();

            mailManager.MailArrived += (sender, eventArgs) =>
            {
                Console.WriteLine("New e-mail!");
                Console.WriteLine(eventArgs.Title);
                Console.WriteLine(eventArgs.Body);
            };
            TimerCallback tcb   = Tcb;
            Timer         timer = new Timer(tcb, mailManager, 0, 1000);

            Thread.Sleep(10000);

            //Prevent GC to collect timer;
            string noOptimization = timer.ToString();
        }
示例#22
0
        /// <summary>
        /// create an instance of MailManager and connect to the MailArrived event
        /// in the handler, output the title and body to the console.
        /// Call the SimulateMailArrived to check the event connection.
        /// Create a System.Threading.Timer, and in the timer callback call SimulateMailArrived every 1 second (=1000 milisc).
        /// Call Thread.Sleep in the main thread to keep the application alive, or call Console.ReadLine.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            var mailManger = new MailManager();

            mailManger.MailArrived += new EventHandler <MailArrivedEventArgs>((object sendr, MailArrivedEventArgs mailArgs) =>
            {
                Console.WriteLine($"New mail arrived!\n Title: {mailArgs.Title}\n body:\n{mailArgs.Body}");
            });
            mailManger.SimulateMailArrived();
            var timer = new System.Threading.Timer(state =>
            {
                Console.WriteLine();
                mailManger.SimulateMailArrived();
            }, null, 0, 1000);

            Console.ReadLine();
            timer.GetType(); //use the timer after the readline command so the Gc won't distroy it
            Console.WriteLine(" we got the expected results :)");
        }
示例#23
0
        static void Main(string[] args)
        {
            MailManager mgr = new MailManager();

            mgr.MailArrived += OnNewMail;
            mgr.MailArrived += (s, e) => {
                Console.WriteLine("Arrived {0}", e.Body);
            };

            mgr.SimulateMailArrived();

//			mgr.MailArrived -= OnNewMail;
            mgr.SimulateMailArrived();

            #region Simulation
            using (Timer t = new Timer(delegate {
                mgr.SimulateMailArrived();
            }, null, new Random().Next(1000) + 400, 1000)) {
                Thread.Sleep(10000);
            }
            #endregion
        }
示例#24
0
        private static void Tcb(object state)
        {
            MailManager mailManager = state as MailManager;

            mailManager?.SimulateMailArrived();
        }