What is the meaning of this error message ?

Spelltox

Member
Joined
Feb 27, 2009
Messages
8
Programming Experience
3-5
"Exception has been thrown by the target of an invocation"

Instead of words, here is my code's logic :


while loop

run BGworker01
run BGworker02
...
run BGworker09

application.doEvents
thread.sleep(10)

end while


All the bgWorkers do the same thing (sending some data, only to different locations).

When i run this loop with only 1 Background-Worker, it's all fine,
but when i add the other bgWorkers i get the mentioned error at the "application.doEvents" part of the loop.
I think it also points to another place (highlighted in green) inside one of the bgworker's code :

Dim FileStreamToSend As FileStream = New FileStream(fileToSend, FileMode.Open)

I thought it might be a problem that all bgWorkers are trying to read from the same file together, but when i tried using different file for each bgWorker, the problem persisted.

I'm in early stages of learning vb.net (and .net in general),
So i would appreciate a simple explanation \ solution :)

Thank in advance !
Spelltox.
 
I would assume that you're having issues because you're trying to refire a BackgroundWorker thread before it's original pass is complete due to the loop.
 
i have a :


If NOT (bgWorker001.IsBusy) then
bgWorker001.RunWorkerAsync
End if


And i think it should give a different error in that case.

Really weird .. :confused:
 
Some method was invoked that threw an exception, this exception is available in InnerException of the TargetInvocationException. You can also enable the Debug>Exceptions... options for debugger to break when exceptions are thrown, by default it only breaks when exceptions are not handled by user (you).
 
Er

Why are you starting a load of backgroundworkers in a loop, doing events (bad idea), sleeping for a second (bad idea) and looping round again?

I think there is a more fundamental problem with the design of your program than the exception youre getting
 
Back
Top