This analyzer detects asynchronous methods that do not accept the CancellationToken parameter.
C# |
Task<string> DemoMethodAsync() {
DoThings();
return Task.FromResult("Success");
}
|
VB |
Private Function DemoMethodAsync() As Task(Of String)
DoThings()
Return Task.FromResult("Success")
End Function
|
All asynchronous methods should accept the CancellationToken parameter and use it to cancel a task if task cancellation was requested. Refer to the Task Cancellation article for more information.
C# |
Task<string> DemoMethodAsync(CancellationToken token) {
token.ThrowIfCancellationRequested();
DoThings(token);
return Task.FromResult("Success");
}
|
VB |
Private Function DemoMethodAsync(ByVal token As CancellationToken) As Task(Of String)
token.ThrowIfCancellationRequested()
DoThings(token)
Return Task.FromResult("Success")
End Function
|