示例#1
0
        static void Main(string[] args)
        {
            "Demonstrate Timer - needed for scheduled persistance in Project #2".title('=');
            Console.Write("\n\n  press any key to exit\n");

            TimerDemo td = new TimerDemo();
            td.schedular.Enabled = true;
            Console.ReadKey();
            Console.Write("\n\n");
        }
示例#2
0
        static void Main(string[] args)
        {
            "Demonstrate Timer - needed for scheduled persistance in Project #2".title('=');
            Console.Write("\n\n  press any key to exit\n");

            TimerDemo td = new TimerDemo();

            td.schedular.Enabled = true;
            Console.ReadKey();
            Console.Write("\n\n");
        }
        /*-------------------Function to implement scheduled save of database after every 5 seconds-------------------*/
        public void scheduledSaveDatabase()
        {
            try
            {
                TimerDemo timer = new TimerDemo();
                timer.schedular.Enabled = true;                                                                //Elapsed event is triggered
                Console.Write("\n\n  Press any key to stop database persistence\n");

                timer.schedular.Elapsed += (object source, ElapsedEventArgs e) =>                              //persist database to xml every 5 sec
                {
                    var keys = db.Keys();
                    persistToXML(keys);
                };
                Console.ReadKey();                                                                             //persisted until a key is pressed by user
                timer.schedular.Enabled = false;
            }
            catch (Exception e)
            {
                WriteLine("\n" + e.Message + "\n");
            }
        }