Click here to Skip to main content
15,877,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Experts,

I have 100000++ Customer records in my database. In which have some customer balance is less then 200$ then we want to recharge those customers balance quickly.If i am working that process by using normal foreach loop then it is taking time .

So i want to work it by using multi threading.

I need to know some questions
How can i pass the 500 customers id to thread.
How can i check the set the number of thread in application.
How can i check Application Load states (Memory and Cpu Usage) for best performance of Application.




Thanks
Posted
Comments
Jibesh 10-Jan-13 2:48am    
why dont you use sql update query to update the value?
[no name] 10-Jan-13 3:01am    
In this procedure i need to charge customer CreditCard and write log and check status... and something more procedures need to be done.
Jibesh 10-Jan-13 3:02am    
Ok got it.

Two Methods I suggest you to do...

1. Write SQL Query to Get Data as you need,
SELECT * FROM Customer WHERE Balance < 200

2. For .Net Framework 4.5 You can also consider Using Parallel Loops,
For That go through this article
Parallel Programming Easier than ever using .NET Framework 4[^]
 
Share this answer
 
Comments
Joezer BH 10-Jan-13 4:44am    
;)
[no name] 10-Jan-13 13:48pm    
For Example You Business is Domain Selling and You want to Provide the Feature of Auto Recharge. In that Case You want to Recharge your Customers if your customer balance is less then Zero . Same Here in our business there the condition is 200. Gotit..
I didn't understand if you do through each line in the DB,
if so, why not select all records that have "WHERE balance < 200"?

and as Jibesh suggested if you need update, that can also be done in one action.
if you need help with threads in order to perform an action on each row of the result

you can check out Sacha's article:
Beginners Guide to Threading in .NET: Part 1 of n[^]
 
Share this answer
 
Comments
Ashok19r91d 10-Jan-13 4:42am    
+5
[no name] 10-Jan-13 13:48pm    
For Example You Business is Domain Selling and You want to Provide the Feature of Auto Recharge. In that Case You want to Recharge your Customers if your customer balance is less then Zero . Same Here in our business there the condition is 200.

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