//get rows from db
foreach(DataRow r in rows)
{
//connect to some other database
//update some record in datatable
//insert record into datatable
//etc...
//...
}
如何使用多线程机制重写上述代码,然后我们可以从多台服务器中受益?
答案 0 :(得分:4)
也许这会有所帮助
IEnumerable<DataRow> items = ...
Parallel.ForEach(items, item => {
...
});