Canceling an Asynchronous Call

A client can cancel an asynchronous call that is in progress if the call object implements the ICancelMethodCalls interface. For objects that use standard marshaling, ICancelMethodCalls is always available for marshaled calls. For objects that use custom marshaling or for calls to server objects within the same apartment, this functionality is available only if the call object implements ICancelMethodCalls.

The client can cancel the call at any time, from when the Begin_ method is called until the Finish_ method returns. If the client cancels the call before calling the Finish_ method, it must call the Finish_ method to clean up the state of the call object. Until the client has done so, any calls to any Begin_ method on the call object will return RPC_E_CALL_PENDING.

ms680119.wedge(en-us,VS.85).gifTo cancel an asynchronous call

  1. Query the call object for ICancelMethodCalls.

  2. Call ICancelMethodCalls::Cancel, and then call Release to release the pointer obtained by the QueryInterface call in step 1.

  3. If the client has not called the Finish_ method already, call it now.

There is no guarantee that the server actually stopped execution of the call. If the client's further work depends on some server state that the call may or may not have changed, the client should determine that state before proceeding.

Related topics

Making an Asynchronous Call

 

 

Community Additions

ADD
Show:
© 2014 Microsoft