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

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

相关文章:

  • 2022-12-23
  • 2021-08-25
  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-11
  • 2021-12-09
  • 2021-07-07
  • 2021-07-08
  • 2021-11-10
  • 2021-10-10
相关资源
相似解决方案