private void Run(AbstractImporter importer, Action whenFinished, Action <int, string> reportProgress) { var worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; importer.ReportProgress += (progress, message) => { worker.ReportProgress(progress, message); }; worker.ProgressChanged += (sender, e) => reportProgress(e.ProgressPercentage, e.UserState.ToString()); worker.DoWork += (sender, e) => importer.Import(); worker.RunWorkerCompleted += (sender, e) => { if (e.Error != null) { _view.DisplayError(e.Error.Message); } else { if (whenFinished != null) { whenFinished(); } } }; worker.RunWorkerAsync(); }
public Source <T> importItem <T>(AbstractImporter <Env, T> importer) { lock (lockObj) { if (!importers.Contains(importer)) { importers.Add(importer); } } return(new Source <T>(importer)); }