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?

asked 26 Jul '10, 14:26

_FRED_'s gravatar image

_FRED_
907
accept rate: 0%


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.

link

answered 26 Jul '10, 16:19

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.4k28
accept rate: 31%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×141
×3
×3
×1

Asked: 26 Jul '10, 14:26

Seen: 410 times

Last updated: 26 Jul '10, 16:19