public async Task <string[]> GetAllLines() { var result = new List <string>(); await Task.Run(() => { var info = Info; if (info != null) { var list = new ConcurrentBag <DividedTextFile>(); var fileNUM = info.FileNames.Count; Parallel.For( 0, fileNUM, i => { var dividedFile = new DividedTextFile(i); var filePath = Path.Combine(InfoFileDirectory, info.FileNames[i]); dividedFile.LoadAllLines(filePath); list.Add(dividedFile); } ); if (list.Count > 0) { var array = list.OrderBy(e => e.Id).ToArray(); foreach (var file in array) { foreach (var line in file.Lines) { result.Add(line); } } } } }); return(result.ToArray()); }
private async Task <string[]> GetLines(long start, long end, long step = 1) { var result = new List <string>(); await Task.Run(() => { var info = Info; if (info != null) { end = Math.Min(end, info.TotalLineNUM - 1); if (start >= end) { return; } var list = new ConcurrentBag <DividedTextFile>(); var fileNUM = info.FileNames.Count; Parallel.For( 0, fileNUM, i => { var fileStart = (info.MaxLineNUM *i); var fileEnd = Math.Min(fileStart + info.MaxLineNUM - 1, end); var lineNUM = (long)(fileEnd - fileStart); if (fileEnd >= start && lineNUM > 0) { var dividedFile = new DividedTextFile(i); var filePath = Path.Combine(InfoFileDirectory, info.FileNames[i]); dividedFile.Load(filePath, fileStart, start, fileEnd, step); list.Add(dividedFile); } } ); if (list.Count > 0) { var array = list.OrderBy(e => e.Id).ToArray(); foreach (var file in array) { foreach (var line in file.Lines) { result.Add(line); } } } } }); return(result.ToArray()); }