Read Sql Data From Multiple Threads
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 yo
Solution 1:
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/
Solution 2:
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
Post a Comment for "Read Sql Data From Multiple Threads"