I have a following fairly simple scenario: Some data needs to be written into a DB (pretty big collection) that can be partitioned. But I have two problems:
Easy one: would like to have an option to print the progress bar, so that would like to know how many records have been inserted so far from time to time (kinda shared counter among the threads).
Harder one: each record needs to be accompanied by a timestamp. The timestamps have a starting time and an interval. The timestamp is unfortunately not a part of the record but in sequential programming can be simply calculating by incrementing the current one by a particular interval.
So far, the question is: how to implement the above constraints properly? Is it somehow possible to separate the loop body from the code that is executing when promoting an iteration (++i
or newTimeStamp = oldTimeStamp.AddSeconds(...)
, so that that kind of code will be always executed on a single thread, contrary to the loop body that will be parallelized? If possible, the code snippet will be very helpful, though I'll be happy to get even any pointers/names/keywords. Thanks.