在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
public partial class Form1 : Form { CountdownEvent hander = new CountdownEvent(10); public static object lock_action = new object(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < 10; i++) { ThreadPool.QueueUserWorkItem(new WaitCallback(Run1), i); } textBox1.Invoke(new Action(() => { textBox1.AppendText("按钮1执行完毕".Log()); })); } private void button2_Click(object sender, EventArgs e) { //ThreadPool.SetMaxThreads(10, 30); for (int i = 0; i < 10; i++) { ThreadPool.QueueUserWorkItem(new WaitCallback(Run2), i); } hander.Wait(); textBox1.AppendText("按钮2执行完毕".Log()); } private void Run1(object str) { Thread.Sleep(1000); textBox1.AppendText(str.ToString().Log()); } private void Run2(object str) { Thread.Sleep(1000); textBox1.AppendText(str.ToString().Log()); hander.Signal(); } }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论