如何在c#中的多个线程上处理大型集合 [英] How to Process large collection on multiple Thread in c#

查看:337
本文介绍了如何在c#中的多个线程上处理大型集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在多个线程上处理大型集合



我想要10个线程,在集合中连续添加记录,如果集合数量达到1000,则处理此集合

再次清除它重复相同的

解决方案

 私有  static   void  BulkCopyTable(DataTable表,SqlConnection dbConnection)
{
使用(SqlBulkCopy s = new SqlBulkCopy(dbConnection))
{
s .BatchSize = 1000 ;
s.DestinationTableName = table.TableName;
Debug.WriteLine( 表:{0},table.TableName);
foreach var table.Columns)
{
s.ColumnMappings.Add(column.ToString(),column.ToString());
Debug.WriteLine(column.ToString());
}
s.WriteToServer(table);
}

table.Clear();
}





这有用吗?

很难从你的问题中知道。


How to Process large collection on multiple Thread

I want to take 10 thread which Continually add record in collection and if collection count goes to 1000 then process this collection
And clear it again repeat same

解决方案

private static void BulkCopyTable(DataTable table, SqlConnection dbConnection)
 {
     using (SqlBulkCopy s = new SqlBulkCopy(dbConnection))
     {
         s.BatchSize = 1000;
         s.DestinationTableName = table.TableName;
         Debug.WriteLine("Table: {0}",table.TableName);
         foreach (var column in table.Columns)
         {
             s.ColumnMappings.Add(column.ToString(), column.ToString());
             Debug.WriteLine(column.ToString());
         }
         s.WriteToServer(table);
     }

     table.Clear();
 }



Does this help?
Hard to know from your question.


这篇关于如何在c#中的多个线程上处理大型集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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