WebClient.CancelAsync causes TargetInvocationException

  • Thread starter Thread starter Cat
  • Start date Start date
C

Cat

I created an array of WebClients like this,
WebClient[] downloaders = new WebClient[10];

And started asynchronous downloading for each WebClients.
When the user wants to cancel the operation,
I did like this,
for(i=0; every downloaders...)
{
downloaders.CancelAsync();
}

This caused TargetInvocationException
Why? Do you know the reason? Please let me know.
Thank you.
 
Did you make the async calls on the downloaders itself like
downloaders.BeginInvoke(...)???
 
No, I used
downloaders.DownloadAsyncData();

I used the cancellation code at the form's Closing event handler.
I found that using the same code other than Closing event,
it didn't causes any problem. Maybe there's something wrong
with the form's closing event and WebClient.
 
If you can send me brief code, I can try to see if I can spot something
wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top