How to method call using Timer in c#

Posted by senthil | 12:09:00 PM | | 0 comments »

this code using the system timer we can call the method. i tried working good. its a easy way to call the method using Timer interval time. Following the sample code:

private void button1_Click(object sender, RoutedEventArgs e)
        {
            aTimer = new System.Timers.Timer(10000);

            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);

            aTimer.Interval = 2000;
            aTimer.Enabled = true;

            Console.WriteLine("Press the Enter key to exit the program.");
            Console.ReadLine();
           
        }

        private static void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            aTimer.Enabled = false;
            Console.WriteLine("The Elapsed event was raised at {0}", e.SignalTime);
        }

0 comments

Related Posts Plugin for WordPress, Blogger...