c# Timer_应用程序中生成定期事件

来源:互联网 发布:淘宝gta5刷钱靠谱吗 编辑:程序博客网 时间:2024/06/04 17:55
     // 摘要:    //     在应用程序中生成定期事件。    [DefaultEvent("Elapsed")]    [DefaultProperty("Interval")]    public class Timer : Component, ISupportInitialize    static class Program    {        private static System.Timers.Timer aTimer;        /// <summary>        /// 应用程序的主入口点。        /// </summary>        [STAThread]        static void Main()        {            // Create a timer with a ten second interval.            aTimer = new System.Timers.Timer(10000);            // Hook up the Elapsed event for the timer.            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);            // Set the Interval to 2 seconds (2000 milliseconds).            aTimer.Interval = 5000;            aTimer.Enabled = true;            Console.WriteLine("Press the Enter key to exit the program.");            Console.ReadLine();               }        // Specify what you want to happen when the Elapsed event is         // raised.        private static void OnTimedEvent(object source, ElapsedEventArgs e)        {            MessageBox.Show(null,"test","test");        }    }

0 0
原创粉丝点击