zoukankan      html  css  js  c++  java
  • C#常用简单线程实例

    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;
    using System.Threading;

    namespace NetWorkCreeper
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }

            private void btnStart_Click(object sender, EventArgs e)
            {
                ThreadStart tstart = new ThreadStart(AddItem);
                Thread thread = new Thread(tstart);
                thread.Start();
            }


            public void AddItem()
            {
                for (int index = 0; index < 100000; index++)
                {

          //lbxBox是ListBox控件
                    lbxBox.Items.Add(string.Format("Item {0}", index));
                }
            }

            private void btnLook_Click(object sender, EventArgs e)
            {
                MessageBox.Show(string.Format("ListBox中一共有{0}项{1}", this.lbxBox.Items.Count, Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "." + DateTime.Now.Millisecond)));
            }
        }
    }

    注意,在调试的时候不要直接执行;要选择“调试”-》“开始执行(不调试)”;这一点一定要谨记,否则会运行报错。

  • 相关阅读:
    Learning_the_bash_Shell_Third_Edition 15/n
    Learning_the_bash_Shell_Third_Edition 14/n
    Learning_the_bash_Shell_Third_Edition 13/n
    cvb源码分析,resful规范,drf,drf序列化组件,95
    rest_framework登录组件,权限组件
    forms组件
    分页器
    基于ajax提交数据
    回顾django内容
    多表操作
  • 原文地址:https://www.cnblogs.com/houzuofeng/p/3253140.html
Copyright © 2011-2022 走看看