zoukankan      html  css  js  c++  java
  • 线程(2)

    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 theard
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            //跨线程访问控件
            private void Button1_Click(object sender, EventArgs e)
            {
                Thread thread = new Thread(()=>
                {
                    for (int i = 0; i < 11; i++)
                    {
                        if (label1.InvokeRequired)
                        {
                           label1.Invoke(new Action<string>(a=> { this.label1.Text = a; }),
                           i.ToString());
                        }
                        Thread.Sleep(1000);
                    }
    
                });
                thread.IsBackground = true;
                thread.Start();
            }
        }
    }
    View Code
  • 相关阅读:
    2020软件工程作业02
    2020软件工程作业01
    并发编程—协程
    并发编程—线程
    并发编程—进程
    python网络编程总结
    前端-Javascript
    前端-jQuery
    前端-CSS
    前端-Html
  • 原文地址:https://www.cnblogs.com/Luck1996/p/12022249.html
Copyright © 2011-2022 走看看