大网数据广告活动
Windows 系统接口

Canceling an Asynchronous Call

· 52CE 我爱测

A client can cancel an asynchronous call that is in progress if the call object implements the ICancelMethodCalls interface.

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.

To 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

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。