1. Computing

CancelInvocation And Forget Added To AsyncCalls :)

By December 16, 2011

Follow me on:

in Delphi Threading :: Just a few days after I wrote the AsyncCalls Unit By Andreas Hausladen - Let's Use (and Extend) It! article Andreas did release a new 2.99 version of AsyncCalls. The IAsyncCall interface now includes three more methods:
  • The CancelInvocation method stopps the AsyncCall from being invoked. If the AsyncCall is already processed, a call to CancelInvocation has no effect and the Canceled function will return False as the AsyncCall wasn't canceled.
  • The Canceled method returns True if the AsyncCall was canceled by CancelInvocation.
  • The Forget method unlinks the IAsyncCall interface from the internal AsyncCall. This means that if the last reference to the IAsyncCall interface is gone, the asynchronous call will be still executed. The interface's methods will throw an exception if called after calling Forget. The async function must not call into the main thread because it could be executed after the TThread.Synchronize/Queue mechanism was shut down by the RTL what can cause a dead lock.
Therefore, no need to use my altered version.

Note, though, that you can still benefit from my AsyncCallsHelper if you need to wait for all async calls to finish with "asyncHelper.WaitAll"; or if you need to cancel the invocation for all not finished (or already cancelled) tasks using "asyncHelper.CancelAll".


Comments are closed for this post.
Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2014 About.com. All rights reserved.