1

I'm using Winforms and I've used a backgroundworker with producer/consumer objects inside. Inside DoWork, I have an object, let's call it Something that has:

Task.Run(() => producer.Produce(_appConfig.ScanPaths));
Task.Run(() => consumer.Consume());

When the consumer encounters an exception, it's not thrown and I can't handle it inside BackgroundWorkerRunWorkerCompleted. I have a

if (e.Error != null || e.Cancelled)
{
...
}

To handle it. Do you guys have any suggestions on how I can cancel the Backgroundworker and pop up an error MessageBox? Or a much better approach on what I'm doing with my producer/consumer tasks? I'd appreciate it. Thanks in advance!

relaxhax
  • 11
  • 3
  • 4
    Note: You should not mix BackgroundWorker and Tasks. Anything you want to do with a BackgroundWorker you can accomplish with the TPL, and you should. – Paw Baltzersen Sep 18 '14 at 13:17

0 Answers0