private async Task BuildResultListing() { var models = new List <SearchResultItemModel>(); var resultsInfoToShow = LinqExtensions.Skip(searchResults, (currentPage - 1) * ResultsPerPage).Take(ResultsPerPage).ToList(); var fileIdToPathMap = await Task.Run(() => folderManager.GetFilePathsFromIds(resultsInfoToShow.Select(x => x.FileId).ToArray())); foreach (var resultInfo in resultsInfoToShow) { if (fileIdToPathMap.TryGetValue(resultInfo.FileId, out string filePath) && File.Exists(filePath)) { var(context, wordIndexInContext) = await WordContext.GetContext(filePath, searchText, resultInfo.CharIndex); var sr = new SearchResultItemModel { ColumnNumber = resultInfo.ColumnNumber, LineNumber = resultInfo.LineNumber, CharIndex = resultInfo.CharIndex, FileName = Path.GetFileName(filePath), SearchText = searchText, FilePath = filePath, Context = context, WordIndexInContext = wordIndexInContext }; models.Add(sr); } } var factor = resultsPanel.ClientSize.Width < Screen.PrimaryScreen.Bounds.Width / 2 ? 1 : 0.75; resultsPanel.SuspendLayout(); resultsPanel.Controls.Clear(); foreach (var item in models) { var srItem = new SearchResultItem(item) { Margin = new Padding(8, 0, 0, 8), Width = (int)(resultsPanel.ClientSize.Width * factor) }; srItem.LinkFollowed += SrItem_LinkFollowed; resultsPanel.Controls.Add(srItem); } resultsPanel.ResumeLayout(); }