#Calculating ranges
I need split the list I get from the select into multiple list so I can use Parallel.For() to generate the next query in different threads.
Nope. You don't need it. Use Parallel.ForEach
that automatically can distribute the load on multiple threads if necessary or use the Partitioner
to calculate the ranges e.g.:
var partitions = Partitioner
.Create(fromInclusive: 0, toExclusive: 100, rangeSize: 30)
.GetDynamicPartitions();
the result
Item1 Item2 0 30 30 60 60 90 90 100
#Improvable
Don't do everything in a single method. Write one method to get the data from the server and another one to process it and/or calculate the partitions. You need to pay more attentions to the separation of concerns. Mixing all features in a single method makes it super hard to maintain and to test.