public void LoadFileParallel(string FileName) { using (StreamReader sr = new StreamReader(FileName)) { List <string> lines = new List <string>(); bool finished = false; while (!finished) { lines.Clear(); for (int i = 0; i < 10000; i++) { if (sr.EndOfStream) { finished = true; break; } lines.Add(sr.ReadLine()); } Parallel.ForEach(lines, l => { var data = l.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); int gridid = int.Parse(data[0]); GridLeach CurrentGrid = null; if (!Grids.TryGetValue(gridid, out CurrentGrid)) //Check if we have read the grid before. No need for the grids to be ordered { CurrentGrid = new GridLeach(gridid); CurrentGrid.SoilID = int.Parse(data[4]); CurrentGrid.DMIGridID = int.Parse(data[5]); CurrentGrid.LandUseID = int.Parse(data[6]); lock (Lock) Grids.Add(gridid, CurrentGrid); } //If the end date is written // DateTime Start = new DateTime(int.Parse(data[1]), int.Parse(data[2]), int.Parse(data[3])).AddDays(-int.Parse(data[7]) + 1); //If the start date is written DateTime Start = new DateTime(int.Parse(data[1]), int.Parse(data[2]), int.Parse(data[3])); CurrentGrid.AddYear(Start, data.Skip(9).Select(v => float.Parse(v)).ToArray()); }); } } }