I'm using the code like below for starting and cancelling operations:
var client = new Sftp();
// Connecting
client.BeginGetFile("Source", "Destination", null, null);
// …
if (NeedToCancel()) {
client.AbortTransfer(); // (*)
}//if
Some times, the code in line (*) called before async operation really started (scheduled), and it does not cancelled. Is this a good idea to subscribe for Sftp::TransferProgress event and aborting operation within? Like this:
var client = new Sftp();
var cancelled = false;
// Connecting
client.TransferProgress += (sender, e) => {
if (cancelled) {
client.AbortTransfer(e.Id);
}//if
};
client.BeginGetFile("Source", "Destination", null, null);
// …
cancelled = NeedToCancel();
Does Sftp class have other case for determinate, that async operation is scheduled and can be cancelled?