In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how System.Timers.Timer regularly executes the program. The introduction in the article is very detailed and has certain reference value. Interested friends must read it!
System.Timers.Timer
The code is as follows:
System.Timers.Timer t = new System.Timers.Timer(5000); //Set the interval to 5 seconds
private void Form1_Load(object sender, EventArgs e)
{
t.Elapsed += new System.Timers.ElapsedEventHandler(Timer_TimesUp);
t.AutoReset = false; //Whether the Elapsed event fires once (false) or all the time (true) at the specified time
}
private void btnStart_Click(object sender, EventArgs e)
{
t.Enabled = true; //Whether the Elapsed event is triggered
t.Start();
}
private void Timer_TimesUp(object sender, System.Timers.ElapsedEventArgs e)
{
//5 seconds after the specified time, trigger this event to output Hello World!!!
System.Diagnostics.Debug.WriteLine("Hello World!!!! ");
}
private void btnStop_Click(object sender, EventArgs e)
{
t.Stop();
System.Diagnostics.Debug.WriteLine("End 5 seconds before specified time!!! ");
}
The web's timed cleanup cache can be
The copy code is as follows:
System.Timers.Timer t = new System.Timers.Timer(5000); //Set the interval to 5 seconds
t.Elapsed += new System.Timers.ElapsedEventHandler(Timer_TimesUp);
t.AutoReset = false; //Whether the Elapsed event fires once (false) or all the time (true) at the specified time
t.Enabled = true; //Whether the Elapsed event is triggered
t.Start();
Five lines of code into gloab.cs Application_Start, start web, start;
If it is the timing of a logic function, you can put the code into the static constructor of the logic function class. When the logic class is executed for the first time, the static constructor will be called, and the timing will start naturally.
The above is "System.Timers.Timer how to execute the program timing" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.