//类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Data;
namespace WindowsFormsApplication1
{
class StartThread
{
int StartNum;//单条线程的处理行数
int StartSum;//线程的处理总行数
string FFName;//方法名字(带类名)
public StartThread(int startSum, int startNum)
{
StartSum = startSum;
StartNum = startNum;
}
public void C1()
{
if (StartSum % StartNum == 0)
{
for (int i = 0; i < StartSum / StartNum; i++)
{
Thread thr = new Thread(new ParameterizedThreadStart(C2));
thr.IsBackground=true;
thr.Start(i);
}
}
else
{
for (int i = 0; i <Convert.ToInt32(StartSum / StartNum)+1; i++)
{
Thread thr = new Thread(new ParameterizedThreadStart(C2));
thr.IsBackground = true;
thr.Start(i);
}
}
}
public void C2(object i)
{
Form1 fr = new Form1();
int a = Convert.ToInt32(i);
int b = Convert.ToInt32(StartSum / StartNum);
if (a == Convert.ToInt32(StartSum / StartNum))
{
fr.thread1(StartNum,a);
}
else
{
fr.thread2(a, StartSum % StartNum, StartNum, Dt);
}
}
}
}
//窗体
private void Form1_Load(object sender, EventArgs e)
{
dt.Columns.Add("Column6");
dt.Columns.Add("C72");
for (int i = 0; i < 109; i++)
{
DataRow dar = dt.NewRow();
dar[0] = i;
dar[1] = i;
dt.Rows.Add(dar);
}
dataGridView1.DataSource = dt;
StartThread th = new StartThread(109, 10);
th.C1();
}
public void thread1(int h, int j )
{
int c = h * j;
for (int i = 0; i < j; i++)
{
dataGridView1.Rows[c].Cells["C7"].Value = c;
c++;
}
}
public void thread2(int j,int a,int b)
{
int m = dt.Rows.Count;
int c = j * b;
for (int i = 0; i < a; i++)
{
dataGridView1.Rows[c].Cells["C7"].Value = c;
c++;
}
} |