将数据表拆分为10个记录的多个表,并使用Threading执行所有表 [英] Split the datatable in to multiple tables of 10 records and execute all the tables using Threading

查看:77
本文介绍了将数据表拆分为10个记录的多个表,并使用Threading执行所有表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表,其中有大量数据.我想将记录分成多个数据表(每个数据表包含10条记录的总和)并在每个线程中调用每个数据表.我该怎么做?

I have a datatable,where I have large quantity of data.I want to split the records in to multiple datatables(each datatable contains a sum of 10 records) and call each datatable in each thread.How can I do that?

推荐答案

不要那样做,只需创建一个线程池并编写一个执行所需处理的线程方法,然后将尽可能多的线程排队即可处理并让它们同时运行.线程池会在有空间的情况下自动执行排队的任何线程.
Instead of doing it that way, just create a thread pool and write a thread method that does the required processing, and queue up as many threads as your system can handle and let them all run simultaneously. The thread pool will automatically execute any thread that''s queued up when there''s room for it to do so.


现在我有3个带有记录的数据表.我正在调用我的方法通过使用3个线程传递这3个数据集.现在网格中已填充数据.但是我在方法中所做的操作是在单击刷新按钮后对数据进行操作.网格,即使我没有在数据库中进行任何更改,也正在发生巨大的变化.请您指教.
DataTable TEMPDT1 =新的DataTable();
TEMPDT1.Clear();
ThreadStart ts = proxy(){试试{TEMPDT1 = LoadGrid(dtTh1); } catch(Exception ex){Console.WriteLine(ex.Message); }};
线程th1 =新线程(ts);

//

DataTable TEMPDT2 =新的DataTable();
ThreadStart ts1 = proxy(){试试{TEMPDT2 = LoadGrid(dtTh2); } catch(Exception ex){Console.WriteLine(ex.Message); };
线程th2 =新线程(ts1);

//
DataTable TEMPDT3 =新的DataTable();
ThreadStart ts2 = proxy(){试试{TEMPDT3 = LoadGrid(dtTh3); } catch(Exception ex){Console.WriteLine(ex.Message); }};
线程th3 =新线程(ts2);


th1.Start();
th1.IsBackground = true;
th2.Start();
//th2.Join();
th2.IsBackground = true;
th3.Start();
//th3.Join();
th3.IsBackground = true;
DataSet oDs = new DataSet();
while(th1.IsAlive || th2.IsAlive || th3.IsAlive)
{
//继续...

}
TEMPDT1.Merge(TEMPDT2,true);
TEMPDT1.Merge(TEMPDT3,true);
Now I have 3 datatables with records.I am calling my method by passing these 3 datatbales using 3 threads.Now the grid is populated with the data.But the operation what I am doing in the method is to manipulate the data after clicking on a refresh button.So again when I am displaying the data in the grid,even though I havent made any changes in the database there is a huge change is occuring.Can u please advice.?

DataTable TEMPDT1=new DataTable();
TEMPDT1.Clear();
ThreadStart ts = delegate() { try { TEMPDT1 = LoadGrid(dtTh1); } catch (Exception ex) { Console.WriteLine(ex.Message); } };
Thread th1 = new Thread(ts);

//

DataTable TEMPDT2=new DataTable();
ThreadStart ts1 = delegate() { try { TEMPDT2 = LoadGrid(dtTh2); } catch (Exception ex) { Console.WriteLine(ex.Message); } };
Thread th2 = new Thread(ts1);

//
DataTable TEMPDT3=new DataTable();
ThreadStart ts2 = delegate() { try { TEMPDT3 = LoadGrid(dtTh3); } catch (Exception ex) { Console.WriteLine(ex.Message); } };
Thread th3 = new Thread(ts2);


th1.Start();
th1.IsBackground = true;
th2.Start();
//th2.Join();
th2.IsBackground = true;
th3.Start();
//th3.Join();
th3.IsBackground = true;
DataSet oDs = new DataSet();
while (th1.IsAlive || th2.IsAlive || th3.IsAlive)
{
//Conti...

}
TEMPDT1.Merge(TEMPDT2,true);
TEMPDT1.Merge(TEMPDT3,true);


这篇关于将数据表拆分为10个记录的多个表,并使用Threading执行所有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆