Click here to Skip to main content
15,907,183 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 8-Dec-14 20:29pm
v3
Comments
Praveen Kumar Upadhyay 9-Dec-14 2:21am    
You want some enqueue and dequeue functionality?
Pradip Jadhav, India 9-Dec-14 2:30am    
Actually i have large collection and i want to bulk insert it into database by 1000 batch

So Suggest any way
Tomas Takac 9-Dec-14 3:57am    
You should update your question with this information and add a tag to tell what database you are using.
Praveen Kumar Upadhyay 9-Dec-14 2:40am    
Can you please elaborate your requirement. So we can help you in a better way rather guessing.
Pradip Jadhav, India 9-Dec-14 2:50am    
i want send sms to customer for sending sms i need to insert record in sms table only

so for sending sms i have 1 cr customer and in my sms text there are some dynamic field like Name

so i decided take 1 collection and create dynamic record on seprate thread and if collection size touch at 1000 i will fire insert



1 solution

C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900