[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;
using SufeinetHttpHelper;
namespace list测试
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listView1.View = View.Details;
listView1.FullRowSelect = true;
}
delegate void Delegate_List(int i, string msg);//申明委托
Delegate_List DL_List;//定义委托变量
private void Form1_Load(object sender, EventArgs e)
{
DL_List = new Delegate_List(ListAdd);//实例化委托
}
//生成关键词按钮
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 1000; i++)
{
ListViewItem item = new ListViewItem();
item.Text = i.ToString();
item.SubItems.Add("");
listView1.Items.Add(item);
}
}
//测试按钮
private void button2_Click(object sender, EventArgs e)
{
int number = Convert.ToInt32(txtNumber.Text.Trim());
for (int ii = 0; ii < number; ii++)
{
Thread objThread = new Thread(new ThreadStart(delegate
{
ThreadMethodTxt(ii);
}));
objThread.Start();
Thread.Sleep(100);
}
}
public void ThreadMethodTxt(int n)
{
this.BeginInvoke(DL_List, n, Thread.CurrentThread.ManagedThreadId.ToString());
}
//添加列的具体方法
private void ListAdd(int i,string msg)
{
listView1.Items.SubItems[1].Text = msg;
}
}