有一些相关信息我需要获取过来后,在一个GRID上显示,但是我发现一个问题.就是数据实时更新的时候,比如我点击或者拖动窗体会造成卡顿或者假死的情况.以下是我模拟数据实时刷新的代码.请问我这种情况该如何考虑?使用多线程?还是?以下代码只是模拟,可能会有歧义.
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 WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 100000; i++)
{
this.dataGridView1.DataSource = getTable(i);
this.dataGridView1.Refresh();
this.dataGridView1.Update();
}
}
public DataTable getTable(int i)
{
DataTable table = new DataTable();
table.Columns.Add("column1", System.Type.GetType("System.String"));
table.Columns.Add("column2", System.Type.GetType("System.String"));
DataRow row = table.NewRow();
row["column1"] = "AXsasas" + i;
row["column2"] = "AAdasdas" + i;
table.Rows.Add(row);
table.AcceptChanges();
return table;
}
private void Form1_Load(object sender, EventArgs e)
{
//getTable();
//this.dataGridView1.DataSource = getTable();
}
}
}