Windows form application でタイマーを使う

目的:一定の時間間隔ごとに特定の処理を行いたい。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace timer
{
    public partial class Form1 : Form
    {
        int value = 0;
        
        public Form1()
        {
            InitializeComponent();

            eventTimer.Interval = 1000; // 1000ミリ秒間隔
            eventTimer.Tick += new System.EventHandler(eventTimer_Tick);
            eventTimer.Enabled = true;

            button1.Text = "Disable timer";
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void eventTimer_Tick(object sender, EventArgs e){
            value += 1;
            textBox1.Text = value.ToString(); 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(eventTimer.Enabled == true){
                eventTimer.Enabled = false;
                button1.Text = "Enable timer";
            }
            else
            {
                eventTimer.Enabled = true;
                button1.Text = "Disable timer";
            }
        }
    }
}