Thread[] threads = new Thread[table_YuanLT.Length];
for (int i = 0; i < table_YuanLT.Length; i++)
{
//构造连接字符串
SqlConnectionStringBuilder builder_new = new SqlConnectionStringBuilder(conn_NewLT);
SqlConnectionStringBuilder builder_yuan = new SqlConnectionStringBuilder(conn_YuanLT);
string table_new = table_NewLT[i];
string table_yuan = table_YuanLT[i];
dataGridView1[0, i].Value = table_yuan;
dataGridView1[1, i].Value = table_new;
threads[i] = new Thread(() => InsertTable(builder_new.ConnectionString, builder_yuan.ConnectionString, table_new, table_yuan));
threads[i].IsBackground = true;
threads[i].Start();
//InsertTable(builder_new.ConnectionString, builder_yuan.ConnectionString, table_new, table_yuan);
threads[i].Abort();
}
定义了一组线程Thread[] threads = new Thread[table_YuanLT.Length];均需要调用 InsertTable(,,,,)函数
threads[i].Abort();干嘛?
我是第一次写有关线程的东西,线程用完不是要终止么?
@Avanti: 不需要,相反你abort了反而有问题。你的期望可能是希望等待线程执行完再继续。
一般写法是var td=new Thread(....)
td.Join();
或者使用CountdownEvent控制数量较多的线程。
线程可不要乱开关
threads[i].Abort();这句删除后,当数据库表table_YuanLT[i]中的数据量非常大时,threads[i]就不调用InsertTable(,,,,)函数了,是怎么回事啊?
@Avanti: 线程也不是想开多少就开多少的