Canceling Asyncronous Calls

  • Thread starter George Nentidis
  • Start date
G

George Nentidis

Hi 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
 
V

Vadym Stetsyak

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...

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
M

Mehdi

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...

When the callback method in invoked, the call has already been completed,
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.
 

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

Top