TargetInvokationException

  • Thread starter Thread starter Andrew Bullock
  • Start date Start date
A

Andrew Bullock

Hi,


Ive got a multithreaded app, which uses bgWorker.RunWorkerAsync() to run
the 2nd, 3rd, ..., nth threads.

I keep getting exceptions thrown by various parts of the
bgWorker.ProgressChanged event. These errors are probably just because
I've done something silly, but thats not what I'm asking for help with...

When these exceptions occur, why do i get a TargetInvokationException
thrown around Application.Run(new frmMain()); in program.cs?

I can view the innerexception to get some details but its a bit of a pain.

What can i do to make the exception in innerexception be thrown at the
actual location where the error occurs?

I'm not using any try catches.

If you need any more code to help troubleshoot this just say :)


Hope someone can help,

Thanks

Andrew
 
Andrew,

I believe this is because the actuall exception is thrown inside the worker
thread. The exceptions are not marshaled between threads, so in the main
thread you get some exception caused as a side effect of the real one.
Try to try/catch the code that might throw an exception.

Other solution is in debug to set the debuger to stop on exception as soon
as they are thrown. Hopefully it will stop on the line where the first
exception happens. This settings you can find under Debug|Exceptions... menu
in VS
 
Back
Top