HttpResponse.ClientDisconnectedToken 属性

定义

获取客户端断开连接时触发的 CancellationToken 对象。Gets a CancellationToken object that is tripped when the client disconnects.

public:
 property System::Threading::CancellationToken ClientDisconnectedToken { System::Threading::CancellationToken get(); };
public System.Threading.CancellationToken ClientDisconnectedToken { get; }
member this.ClientDisconnectedToken : System.Threading.CancellationToken
Public ReadOnly Property ClientDisconnectedToken As CancellationToken

属性值

CancellationToken

取消标记。The cancellation token.

注解

此 API 是线程安全的。This API is thread-safe. 但对于应使用取消令牌的方式有一些限制。However, there are some restrictions on how the cancellation token should be used. 如果使用不当,可能会导致争用条件、死锁或其他意外行为。Using it incorrectly can lead to race conditions, deadlocks, or other unexpected behavior. 请记住以下准则:Keep in mind the following guidelines:

  • 确保不在单个请求的边界之外调用此 API,因为 ASP.NET 将在请求结束时释放取消标记。Ensure that you don't call into this API outside the bounds of a single request, because ASP.NET will dispose of the cancellation token at the end of the request. 不保证令牌在被释放之前将转换为已取消状态。There is no guarantee that the token will ever transition to a canceled state before it is disposed. 例如,如果请求在客户端没有断开连接的情况下完成,则会在未事先取消的情况下释放令牌。For example, if the request finishes without the client having disconnected, the token will be disposed without having first been canceled.

  • 不要等待 CancellationToken.WaitHandle ,因为这违背了异步通知的目的,并可能导致死锁。Do not wait on the CancellationToken.WaitHandle, as this defeats the purpose of an asynchronous notification and can cause deadlocks.

  • 不要调用对 CancellationToken.Register 原始对象调用回调的重载 SynchronizationContextDo not call the CancellationToken.Register overloads which invoke the callback on the original SynchronizationContext object.

  • 不要在 HttpContext 提供给方法的回调中使用对象或其他非线程安全的 ASP.NET 内部对象 CancellationToken.RegisterDo not use the HttpContext object or other non-thread-safe ASP.NET intrinsic objects from within the callback provided to the CancellationToken.Register method. 回调可能与其他 ASP.NET 或应用程序代码同时运行。The callback may be running concurrently with other ASP.NET or application code.

  • 保留回调方法简短运行和非阻塞。Keep the callback methods short-running and non-blocking.

  • 请尽力避免从回调方法中引发异常。Make every effort to avoid throwing exceptions from within the callback methods.

此属性仅在集成模式下 (IIS) 7.5 或更高版本的 Internet 信息服务中受支持。This property is only supported in Internet Information Service (IIS) 7.5 or higher in integrated mode. 如果在没有正确的 IIS 版本或管道模式的情况下调用它,则 PlatformNotSupportedException 会引发。If you invoke it without the right IIS version or pipeline mode, a PlatformNotSupportedException is thrown. 若要确定 IIS 版本,请使用 IISVersionTo determine the IIS version, use IISVersion. 若要确定管道模式,请使用 UsingIntegratedPipelineTo determine the pipeline mode, use UsingIntegratedPipeline.

适用于