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

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

  • 相关阅读:
    浅谈求卡特兰数的几种方法
    WPF基础知识、界面布局及控件Binding
    .net平台下C#socket通信(上)
    .net泛型理解
    面向过程和面向对象及面向对象的三大特征
    C#配置文件管理
    MOGRE学习笔记(3)--MOGRE小项目练习
    委托、事件学习笔记
    MOGRE学习笔记(2)
    MOGRE学习笔记(1)
  • 原文地址:https://www.cnblogs.com/houzuofeng/p/3253140.html
Copyright © 2011-2022 走看看