C#

C#

Made by DeepSource

CancellationToken parameter should always be placed last in the parameter list CS-R1141

Anti-pattern
Minor

Asynchronous operations or long-running tasks that are cancelable can take in a CancellationToken which helps in terminating these operations. It is common for asynchronous operations to pass around this token as they invoke other such operations, thereby aiding in terminating the call chain. Microsoft guidelines state that this CancellationToken be always placed at last in the parameter list unless there are optional parameters or parameters with ref or out modifiers. While the token itself is not usually relevant to the core functionality of a majority of these methods, it is considered a good API design practice to have such parameters be the last parameter in the list.

Bad Practice

void M(char c, int i, CancellationToken t, double d);

Recommended

void M(char c, int i, double d, CancellationToken t);

References