private async Task OpenFiles(String[] paths) { logTabs.Visible = true; foreach (var filename in paths) { /*if log already watched select relative tab*/ FileInfo file = new FileInfo(filename); var values = fullPathTabAssociation.Where(x => x.Key == file.FullName); int indexOfExistingTab = (!values.Any()) ? -1 : values.FirstOrDefault().Value; if (indexOfExistingTab != -1) { logTabs.SelectedIndex = indexOfExistingTab; return; } /*else it creates it and associates the fullName with tab index, for uniqueness*/ fullPathTabAssociation.Add(file.FullName, logTabs.TabCount); LogPanel logPanel = null; try { logTabs.TabPages.Add(new TabPage(file.Name)); logTabs.SelectedIndex = logTabs.TabCount - 1; logPanel = new LogPanel(file.FullName); logTabs.SelectedTab.Controls.Add(logPanel); } catch (Exception ex) { fullPathTabAssociation.Remove(file.FullName); MessageBox.Show(ex.Message); if (logTabs.TabCount == 0) { logTabs.Visible = false; } return; } /*read the file in the specified direction*/ await logPanel.LoadAsync(); } }