Creation et arret d'un Thread

L'exemple ci dessous crée un thread qui execute DoTask() toutes les 3 secondes. Pour arreter le Thread, il suffit de mettre ThreadStop = true;

|Exemple Thread
        private void buttonStart_Click(object sender, EventArgs e)
        {
            (new Thread(new ThreadStart(() =>
            {
                while (!ThreadStop)
                {
                    System.Threading.Thread.Sleep(3000);
                    DoTask();
                }
            }
            ))).Start();
        }
 
        private void buttonStop_Click(object sender, EventArgs e)
        {
            ThreadStop = true;
        }
 
        void DoTask()
        {
            if (InvokeRequired)
            {
                BeginInvoke(new MethodInvoker(DoTask));
                return;
            }
            progressBar1.Value++;
        }