C timer a method that implements automatic execution

  • 2020-12-19 21:09:17
  • OfStack

This article illustrates the C# timer method for automatic execution. Share to everybody for everybody reference. Specific implementation methods are as follows:


// Here is 1 Something that opens a form timing execution button private void Form1_Load(object sender, EventArgs e)
{
System.Timers.Timer pTimer = new System.Timers.Timer(5000);// every 5 Seconds to perform 1 Didn't work time, winfrom built-in
pTimer.Elapsed+=pTimer_Elapsed;// Delegate, the method to execute
pTimer.AutoReset = true;// Get the timer to execute automatically
pTimer.Enabled = true;// this 1 Make sure it does, or the timer won't execute
Control.CheckForIllegalCrossThreadCalls = false;// This is not very clear, it needs to be studied } private void pTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
button1_Click(null, null);
}   private void button1_Click(object sender, EventArgs e){}

Hopefully this article has helped you with your C# programming.


Related articles: