一款简单易用的基础网络通讯组件库。

SystemThreadingExtensionWithCancellationT(TaskT, CancellationToken) 方法

Wraps a task with one that will complete as cancelled based on a cancellation cancellationToken, allowing someone to await a task but be able to break out early by cancelling the cancellationToken.

Definition

命名空间: TouchSocket.Core
程序集: TouchSocket.Core (在 TouchSocket.Core.dll 中) 版本:4.0.0-beta.143+5fcca7a4e70968794985dc3793adc50531308be6
C#
public static Task<T> WithCancellation<T>(
	this Task<T> task,
	CancellationToken cancellationToken
)

参数

task  TaskT
The task to wrap.
cancellationToken  CancellationToken
The cancellationToken that can be canceled to break out of the await.

类型参数

T
The type of value returned by the task.

返回值

TaskT
The wrapping task.

备注

在 Visual Basic 和 C# 中,这个方法可以当成为类型 TaskT 的实例方法来调用。在采用实例方法语法调用这个方法时,请省略第一个参数。请参考 扩展方法 (Visual Basic)扩展方法 (C# 编程指南) 获取更多信息。

参见