HttpResponse.ClientDisconnectedToken 屬性


取得用戶端中斷連接時發生錯誤的 CancellationToken 物件。Gets a CancellationToken object that is tripped when the client disconnects.

 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


取消語彙基元。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 會在要求結束時處置取消 token。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在原始SynchronizationContext物件上叫用回呼的多載。Do not call the CancellationToken.Register overloads which invoke the callback on the original SynchronizationContext object.

  • 請勿從提供CancellationToken.RegisterHttpContext方法的回呼內,使用物件或其他非安全線程的 ASP.NET 內建物件。Do 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.

只有在整合模式中的 Internet Information Service (IIS)7.5 或更高版本才支援此屬性。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 版本,請IISVersion使用。To determine the IIS version, use IISVersion. 若要判斷管線模式,請UsingIntegratedPipeline使用。To determine the pipeline mode, use UsingIntegratedPipeline.