0 votes
by (640 points)
edited

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?

Applies to: Rebex SFTP

1 Answer

+1 vote
by (134k points)
edited
 
Best answer

Yes, calling AbortTransfer from a TransferProgress event handler is perfectly acceptable.

We don't currently have any method to determine the state of async operation. But I would say that the current behavior (inability to cancel async operation before it really started) is not right and that it should be possible to use AbortTransfer right after BeginGetFile (or other methods) return. We will fix this for the next release of Rebex SFTP.

...