public void fetchBytesOfFiles(string[] pathOfFiles) { try { parent_Grid.Dispatcher.Invoke(new Action(delegate { parent_Grid.BeginDataUpdate(); }), System.Windows.Threading.DispatcherPriority.DataBind); foreach (string filePath in pathOfFiles) { bool isDirectory = filePath.IsDirectory(); string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(filePath); string fileType = (isDirectory) ? @"<Folder>" : System.IO.Path.GetExtension(filePath); long fileSizeInBytes = (isDirectory) ? GetDirectorySize(filePath) : GetFileSize(filePath); TreeListNode node = new TreeListNode() { Content = new RowItem(fileNameWithoutExtension, fileType, fileSizeInBytes, filePath) }; node.IsExpandButtonVisible = (isDirectory && HasFiles(filePath)) ? DefaultBoolean.True : DefaultBoolean.False; writeFileBytesOnTheRAM(node); parent_TreeListView.Dispatcher.Invoke(new Action(delegate { parent_TreeListView.Nodes.Add(node); }), System.Windows.Threading.DispatcherPriority.DataBind); if (node.IsExpandButtonVisible == DefaultBoolean.True) { InitOneFolder(node); } parent_TreeListView.Dispatcher.Invoke(new Action(delegate { parent_TreeListView.CollapseAllNodes(); }), System.Windows.Threading.DispatcherPriority.Render); } } catch (IOException io) { parent_Window.Dispatcher.Invoke(new Action(delegate { MsgBox.Show(io.Message, io.Source, parent_Window); }), System.Windows.Threading.DispatcherPriority.Render); } catch (Exception ex) { parent_Window.Dispatcher.Invoke(new Action(delegate { MsgBox.Show(ex.Message, ex.Source, parent_Window); }), System.Windows.Threading.DispatcherPriority.Render); } finally { parent_Grid.Dispatcher.Invoke(new Action(delegate { parent_Grid.EndDataUpdate(); }), System.Windows.Threading.DispatcherPriority.DataBind); } }