zoukankan      html  css  js  c++  java
  • 线程

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace WindowsFormsApp1
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    Thread thread;

    /// <summary>
    /// 启动线程
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button1_Click(object sender, EventArgs e)
    {

    ThreadStart threadStart = new ThreadStart(SetText);
    thread = new Thread(threadStart);
    thread.Start();
    }
    /// <summary>
    /// 睡眠
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button2_Click(object sender, EventArgs e)
    {
    Thread.Sleep(5000);
    }

    /// <summary>
    /// 挂起
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [Obsolete]
    private void button3_Click(object sender, EventArgs e)
    {


    if (thread.ThreadState!=ThreadState.Suspended)
    {
    thread.Suspend();
    }

    }

    /// <summary>
    /// 恢复
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [Obsolete]
    private void button4_Click(object sender, EventArgs e)
    {
    if (thread.ThreadState == ThreadState.Suspended)
    {
    thread.Resume();
    }
    }

    /// <summary>
    /// 终止线程
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button5_Click(object sender, EventArgs e)
    {
    thread.Abort();
    }
    /// <summary>
    /// 带参数线程
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button6_Click(object sender, EventArgs e)
    {

    ThreadStart threadStart = new ThreadStart(SetTextTwo);
    thread = new Thread(threadStart);
    thread.Start();

    }

    /// <summary>
    /// 文本框赋值
    /// </summary>
    /// <param name="par"></param>
    public void SetText()
    {
    for (int i = 0; i <= 100000; i++)
    {
    textBox2.Invoke(new Action(() => { textBox2.Text = "第" + i + "条记录同步完成"; }));
    progressBar1.Invoke(new Action(() => { progressBar1.Value = i; }));
    label2.Invoke(new Action(() => { label2.Text = Math.Round(Convert.ToDouble(i) / 1000.00, 2) + "%"; }));
    }
    }


    /// <summary>
    /// 文本框赋值
    /// </summary>
    /// <param name="par"></param>
    public void SetTextTwo()
    {
    for (int i = 0; i <= 100000; i++)
    {
    textBox2.Invoke(new Action(() => { textBox2.Text=$"[{textBox1.Text}]第" + i + "条记录同步完成"; }));
    progressBar1.Invoke(new Action(() => { progressBar1.Value = i; }));
    label2.Invoke(new Action(() => { label2.Text = Math.Round(Convert.ToDouble(i) / 1000.00, 2) + "%"; }));
    }
    }

    }
    }

  • 相关阅读:
    测试策略如何制定
    python atexit模块和register函数
    使用Redis实现异步消息队列
    python 处理中文 读取数据库输出全是问号
    TCP和UDP的区别和优缺点
    怎样ping网络
    ImportError: libpng12.so.0: cannot open shared object file: No such file or directory
    tensorrtx/retinaface/calibrator.cpp:4:31: 致命错误:opencv2/dnn/dnn.hpp:没有那个文件或目录
    编译tensorrtx/retinaface遇到报错/usr/local/cuda/include/vector_types.h(421): error: identifier "constexpr" is undefined
    RetinaFace.cpp:112:37: 错误:‘std::chrono’尚未声明
  • 原文地址:https://www.cnblogs.com/ryzryz/p/12159905.html
Copyright © 2011-2022 走看看