1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
List<Pt> points = new List<JMDNParcelle.Pt>(dtPoints.Rows.Count);
int totalCount = 0, count = 0, i=0;
Object obj = new Object();
var maListeDeListesDePoints = dtPoints.Rows.OfType<System.Data.DataRow>().GroupBy(x => i++ / 5).Select(x => x.ToList()).ToList(); // Constitue des listes de 5 points
totalCount = maListeDeListesDePoints.Count;
await Task.Run(() =>
Parallel.ForEach(maListeDeListesDePoints, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount / 2 }, listeDePoints => {
for (int j = 0; j < listeDePoints.Count; j++)
{
DataRow drPoint = listeDePoints[j];
DataRow[] drsPCodes = dtPCodes.Select("IdPoint = " + drPoint["IdPoint"]);
List<int> lstPCodes = new List<int>();
foreach (DataRow drPCode in drsPCodes)
{
int pcode = 0;
if (drPCode != null && int.TryParse(drPCode["PCode"].ToString(), out pcode))
lstPCodes.Add(pcode);
}
Pt newPoint = new Pt(drPoint["nomPoint"].ToString(), (double)drPoint["PointX"], (double)drPoint["PointY"], lstPCodes, srid);
if (newPoint != null)
lock(obj)
points.Add(newPoint);
}
if (progress != null)
progress.Report((count++ * 100 / totalCount));
})
);
if (points != null && points.Count > 0)
return new ObservableCollection<Pt>(points.Distinct());
return null; |