Reputation: 1955
I have a simple task - to read data from SQL table, process it, and once finished - update a field in DB (set processed=true), so every record should be processed only once.
Can you advise me, what technique can I use to do it multi-threaded? It means, read data from table in multiple threads.
Upvotes: 1
Views: 4239
Reputation: 36
If you want to read data in multiple threads without overlapping then you might try paging. You could have each thread read a different page. For example, you could have the first thread read the first 20 records, process each of those records, and then set processed=true for each, while the second thread is doing the same for the next 20 records and so on.
Check out this link for more info on paging in multiple threads. http://ericniemiec.wordpress.com/2010/06/10/paging-records-in-sql-server-2008-for-processing-database-records-on-different-threads-in-c/
Upvotes: 2
Reputation:
If you use ef and use DataContext you should know DataContext is not thread safe.Database Management Systems like MsSQL Is thread safe. i prefer you that read this question
Upvotes: 1