creation_d_un_thread
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++; }
creation_d_un_thread.txt · Dernière modification : 2017/12/06 16:13 de 127.0.0.1