PC Review


Reply
Thread Tools Rate Thread

Canceling an asynchronous delegate

 
 
Diego Diaz
Guest
Posts: n/a
 
      19th Aug 2003
Hello,

I'm facing the situation in which I need to cancel the
execution of a delegate that was started asynchronously
(through BeginInvoke and EndInvoke), but there is
no "CancelInvoke" or something like that. I noticed that
the interface for executing WebServices asynchronously
does have a method for this purpose, but unfortunately
there is a bug in .NET executing WebServices
asynchronously, so I had to wrap my proxy class with an
object so I can execute the WebService synchronously, but
in a different thread (through a local delegate);
however, now the problem is that I can't cancel it in a
safe manner (if I just ignore the running delegate,
subsequent executions of the proxy might start failing).

What do I need to do in order to cancel the execution of
an asynchronous delegate? Is it enough just to
call "Close" on the IAsyncResult pointer?

Thanks a lot in advance,

Diego Diaz
 
Reply With Quote
 
 
 
 
Yan-Hong Huang[MSFT]
Guest
Posts: n/a
 
      19th Aug 2003
Hello Diego,

Thanks for posting in the group.

Aysnc. delegates use the thread pool, which provides no interface to cancel pending or executing requests. So there is no
way to abort an async call made through a delegate. Sometimes, programmers may suggest: "the results of the async call,
when it completes are held by the IAsyncResult objects returned by BeginInvoke. if you just let the IAsyncResult object to
go out of scope, it will be garbage collected and the results of the call will go away. The call will still complete, however."
This method is not recommended because it may break in the future and leak memory.

You need to either use your own thread and abort it when you need to kill the operation prematurely, or set some global flag
that the asysnc. delegate checks, and returns early if the flag is set.

Hope that helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Content-Class: urn:content-classes:message
!From: "Diego Diaz" <(E-Mail Removed)>
!Sender: "Diego Diaz" <(E-Mail Removed)>
!Subject: Canceling an asynchronous delegate
!Date: Mon, 18 Aug 2003 21:32:57 -0700
!Lines: 23
!Message-ID: <070701c3660a$f727e980$(E-Mail Removed)>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Thread-Index: AcNmCvclOxLKq7nETOCbTK+27h+zvw==
!Newsgroups: microsoft.public.dotnet.framework
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:51569
!NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
!X-Tomcat-NG: microsoft.public.dotnet.framework
!
!Hello,
!
!I'm facing the situation in which I need to cancel the
!execution of a delegate that was started asynchronously
!(through BeginInvoke and EndInvoke), but there is
!no "CancelInvoke" or something like that. I noticed that
!the interface for executing WebServices asynchronously
!does have a method for this purpose, but unfortunately
!there is a bug in .NET executing WebServices
!asynchronously, so I had to wrap my proxy class with an
!object so I can execute the WebService synchronously, but
!in a different thread (through a local delegate);
!however, now the problem is that I can't cancel it in a
!safe manner (if I just ignore the running delegate,
!subsequent executions of the proxy might start failing).
!
!What do I need to do in order to cancel the execution of
!an asynchronous delegate? Is it enough just to
!call "Close" on the IAsyncResult pointer?
!
!Thanks a lot in advance,
!
!Diego Diaz
!


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Canceling out of a delegate or IComparable superjodash@gmail.com Microsoft C# .NET 2 12th Mar 2008 11:52 AM
Asynchronous Delegate Question =?Utf-8?B?U3VzYW4=?= Microsoft C# .NET 7 14th Aug 2006 02:00 PM
asynchronous invocation of a delegate in VB Dave Hall Microsoft Dot NET Framework 0 10th Mar 2005 02:06 AM
How to kill an asynchronous delegate? Stewart Microsoft Dot NET Framework 3 26th Dec 2004 11:11 PM
Re: How to terminate an Asynchronous delegate? Alex Feinman [MVP] Microsoft Dot NET Compact Framework 0 20th May 2004 05:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:47 AM.