I load huge files into memory, but with this calculation my application freezes.
Any idea what the problem is with my code?
public void Drop(DragEventArgs args) { BackgroundWorker worker = new BackgroundWorker(); string fileName = IsSingleTextFile(args); if (fileName == null) return; worker.DoWork += (o, ea) => { try { StreamReader fileToLoad = new StreamReader(fileName); string filecontent = fileToLoad.ReadToEnd(); fileToLoad.Close(); // providing the information to the UI thread Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => SfmLogFile = filecontent)); } catch (Exception) { throw; } }; worker.RunWorkerCompleted += (o, ea) => { args.Handled = true; IsBusy = false; }; // Mark the event as handled, so TextBox native Drop handler is not called. IsBusy = true; worker.RunWorkerAsync(); }
source share