parallel.for

Can I use Parallel.For with sql Commands?

落花浮王杯 提交于 2019-11-29 08:44:03
I have a class of range public class avl_range { public long start { get; set; } public long end { get; set; } } If I use a normal FOR works perfect, but have to wait for each command to finish and each query take 8 seconds, so 10 queries take 80 seconds. In the Parallel version If I only print the ranges works perfect, but if try to execute the command say is already in progress. {"An operation is already in progress."} How can I solve this? var numbers = new List<avl_range>(); using (var conn = new NpgsqlConnection(strConnection)) { conn.Open(); Action<avl_range> forEachLoop = number => /

Can I use Parallel.For with sql Commands?

隐身守侯 提交于 2019-11-27 19:02:59
问题 I have a class of range public class avl_range { public long start { get; set; } public long end { get; set; } } If I use a normal FOR works perfect, but have to wait for each command to finish and each query take 8 seconds, so 10 queries take 80 seconds. In the Parallel version If I only print the ranges works perfect, but if try to execute the command say is already in progress. {"An operation is already in progress."} How can I solve this? var numbers = new List<avl_range>(); using (var