zoukankan      html  css  js  c++  java
  • C# 线程池执行操作例子

    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();
    }


    }

  • 相关阅读:
    note
    deep learning
    matlab远程调试
    faster rcnn
    十一旅行
    python生成随机数
    python 读取mat文件
    opencv anaconda
    python文件操作
    python换行
  • 原文地址:https://www.cnblogs.com/zxtceq/p/7825834.html
Copyright © 2011-2022 走看看