日期:2014-05-17 浏览次数:21031 次
private int nMaxThreads, nThreads;
public delegate void CB_SetDataGridViewInfo(DataGridViewRow dgvr);
public void Deg_SetDataGridViewInfo(DataGridViewRow dgvr)//委托的方法
{
if (this.dataGridViewX1.InvokeRequired)
{
CB_SetDataGridViewInfo cs = new CB_SetDataGridViewInfo(Deg_SetDataGridViewInfo);
this.BeginInvoke(cs, new object[] { dgvr });
}
else
{
dataGridViewX1.Rows.Add(dgvr);
dataGridViewX1.FirstDisplayedScrollingRowIndex = dataGridViewX1.Rows.Count;
}
}
private void Thd_Start(object objPara)//线程
{
do something.........//主要工作
DataGridViewRow dgvr = new DataGridViewRow();
dgvr.CreateCells(dataGridViewX1);
for (int i = 0; i < 10; i++)
{
dgvr.Cells[i].Value = i;//这里是工作后的结果,用i临时代替一下
}
lock(this)
{
nThreads -= 1;//线程数减一
}
Deg_SetDataGridViewInfo(dgvr);// 托管调用
}
private void btxStart_Click(object sender, EventArgs e)
{
if (tbxOpenFile.Text == null)
{
MessageBox.Show("请选择数据文件!");
return;
}
string[] strLines = File.ReadAllLines(tbxOpenFile.Text, Encoding.Default);
int nRows = strLines.Length;//总行数
nMaxThreads = (int)nUDThread.Value;
nThreads = 0;
int nNow = 0;
do
{
if (nThreads < nMaxThreads)//比较线程数有没有到最大限制
{
int nT = nMaxThreads - nThreads;
for (int i = 0; i < nT; i++)
&nbs