Esempio n. 1
0
 /// <summary>
 /// Starts threads for grabbing Urls using the specified arguments.
 /// </summary>
 public void Start()
 {
     _cancellationPending = false;
     IsBusy = true;
     BackgroundWorker worker = new BackgroundWorker();
     worker.DoWork += (s, dwe) =>
     {
         var db = new SqLiteDal();
         var jobs = db.GetScheduledGrabs(true);
         dwe.Result = jobs;
         //ManualResetEvent[] waitEvents = new ManualResetEvent[ThreadCount];
         //for (int i = 0; i < ThreadCount; i++) {
         //    try {
         //        ManualResetEvent doneEvent = new ManualResetEvent(false);
         //        if (ThreadPool.QueueUserWorkItem(new WaitCallback(ParseUrl), new UrlGrabThreadInfo(doneEvent, i))) {
         //            waitEvents[i] = doneEvent;
         //            _logger.Log(string.Format("Started download thread #{0}", i));
         //        } else {
         //            _logger.Log(string.Format("Error starting download thread #{0}", i), true);
         //        }
         //    } catch (Exception ex) {
         //        _logger.Log(string.Format("Error starting download thread #{0}", i, true) + ": " + ex.Message, true);
         //    }
         //}
         //WaitHandle.WaitAll(waitEvents);
         //dwe.Result = new GrabCompleteEventArgs(ParsedUrls);
     };
     worker.RunWorkerCompleted += (s, rwe) =>
     {
         if (rwe.Error != null) {
             Logger.Log("Error starting grabbing URLs" + ": " + rwe.Error.Message, true);
             if (GrabFailed != null)
                 GrabFailed(this, EventArgs.Empty);
             IsBusy = false;
         } else {
             Jobs = new ObservableCollection<GrabJob>();
             var jobsToRun = rwe.Result as IEnumerable<ScheduledGrab>;
             GrabUrls(jobsToRun);
         }
     };
     worker.RunWorkerAsync();
 }
Esempio n. 2
0
 private void RefreshScheduledGrabs()
 {
     BackgroundWorker worker = new BackgroundWorker();
     ObservableCollection<ScheduledGrab> grabs = null;
     ObservableCollection<GrabTemplate> templates = null;
     worker.DoWork += (s, dwe) =>
         {
             var db = new SqLiteDal();
             grabs = new ObservableCollection<ScheduledGrab>(db.GetScheduledGrabs(null));
             templates = new ObservableCollection<GrabTemplate>(db.GetTemplates());
         };
     worker.RunWorkerCompleted += (Fs, rwe) =>
         {
             if (rwe.Error != null) {
                 DialogBox.ShowAlert(this, rwe.Error.Message, "Error");
             } else {
                 ScheduledGrabs = grabs;
                 TemplatesProvider.ObjectInstance = templates;
             }
         };
     worker.RunWorkerAsync();
     WPFUtils.WaitForWorker(worker);
     CommandManager.InvalidateRequerySuggested();
 }