|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Canceling Asyncronous CallsHi there all,
I am starting an asyncronous call to a method passing a callback delegate. (More specifically a BeginRead in a network stream). But there are times that I wish to cancel the asynchronous call before it finishes, before the delegate is called. How can I do that? Any ideas? Thank you all in advance... George Hello, George!
GN> I am starting an asyncronous call to a method passing GN> a callback delegate. GN> (More specifically a BeginRead in a network stream). GN> But there are times that I wish to cancel the asynchronous call GN> before it finishes, before the delegate is called. GN> How can I do that? Any ideas? AFAIK you can cancel it when you're in the callback method, just do not call EndRead... On Thu, 9 Mar 2006 19:48:10 +0200, Vadym Stetsyak wrote:
> Hello, George! When the callback method in invoked, the call has already been completed,> > GN> I am starting an asyncronous call to a method passing > GN> a callback delegate. > GN> (More specifically a BeginRead in a network stream). > GN> But there are times that I wish to cancel the asynchronous call > GN> before it finishes, before the delegate is called. > GN> How can I do that? Any ideas? > > AFAIK you can cancel it when you're in the callback method, just do not call EndRead... it's too late. Not calling EndRead will simply create a memory leak. You MUST call EndXXX for every BeginXXX that you've called or you'll end up with memory (and possibly other ressources as well) leaks. The only exception to this rule is the Control.BeginInvoke() method which doesn't require you to call the corresponding Control.EndInvoke() method. As for the OP question, i'm afraid that unless the class that you are using provides an explicit way to cancel an asynchronous operation, there is nothing that you can do apart from ignoring the results in your callback function. |
|||||||||||||||||||||||