using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { System.Threading.Thread.Sleep(10000); } } }
public partial class Form1 : Form { Thread _Thread; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (_Thread == null) { _Thread = new Thread(new ThreadStart(ThreadMethod)); } _Thread.Start(); // attention au 2e appui sur le bouton: quoi faire? } private void ThreadMethod() { // ton analyse ici Thread.Sleep(10000); } }
public partial class Form1 : Form { Thread _Thread; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (_Thread == null) { _Thread = new Thread(new ThreadStart(ThreadMethod)); _Thread.Start(); } } private void ThreadMethod() { // ton analyse ici Thread.Sleep(10000); _Thread = null; } }
public void ThreadMethod() { // update UI this.Invoke((MethodInvoker)delegate { label1.Text = "---" + i.ToString(); }); }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionusing System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace testThread { public partial class Form1 : Form { System.Threading.Thread _Thread; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (_Thread == null) { _Thread = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadMethod)); _Thread.Start(); } } public void ThreadMethod() { // ton analyse ici for (int i = 0; i < 5; i++) { System.Threading.Thread.Sleep(10000); label1.Text = "---" + i.ToString(); } _Thread = null; } } }