0

The exception is in the designer on the line:

base.Dispose(disposing);

It happen sometimes after starting a backgroundworker and then while the backgrounworker is working i'm clicking on the form1 X on the right top corner to close the program.

Sometimes it might not happen the exception and sometimes it does.

Maybe i should handle the backgroundworker on the form1 closed or closing event ? If so what should i do in the event ?

  • You likely have some kind of multi-threading race condition. Hard to tell more unless we see code that reproduces the problem. The BackgroundWorker should *not* be handling any events for form classes. Who is calling `CreateHandle`? That should *never* be happening from a BackgroundWorker, either. – Cody Gray - on strike Jul 05 '16 at 13:41
  • It is up to you to ensure that the worker has stopped before you allow the form to close. So you can be sure that its ProgressChanged and RunWorkerCompleted events can no longer fire. That invariably *does* mean that you have to delay the form closure since you cannot instantly stop the worker and if you try anyway then you'll get a deadlock. – Hans Passant Jul 05 '16 at 13:57

0 Answers0