Support Co-operative Cancellation of all methods that can.
The current suggested method to cancel an operation is setting a
https://winscp.net/eng/docs/library_filetransferprogresseventargs#cancel
This is an anti-pattern in C#. I'm not even sure how my event handling delegate would know if cancellation is requested. An event handling delegate is usually a
The cancellation pattern in C# is generally to pass a
If the transfer method had this token it would simply set the:
Whenever a new
bool
on an FileTransferProgressEventArgs
.
https://winscp.net/eng/docs/library_filetransferprogresseventargs#cancel
This is an anti-pattern in C#. I'm not even sure how my event handling delegate would know if cancellation is requested. An event handling delegate is usually a
static
method that has no knowledge of its own. Plus the event comes in on a different thread from where the transfer occurred.
The cancellation pattern in C# is generally to pass a
CancellationToken
to each operation that supports cancellation as a final, optional, argument. This way you can cancel a single download but not effect an upload elsewhere.
If the transfer method had this token it would simply set the:
FileTransferProgressEventArgs.Cancel = CancellationToken.IsCancellationRequested
FileTransferProgressEventArgs
is created. This way, it cancels itself co-operatively and the cancelled state is then visible in the next event. The event tells you information, not the other way around.