login about faq

This is a helper function for handling the async Ftp2 process within a native async/await app. I ran into an issue the other day when the Ftp2 task started returning -1, but Task.TaskSuccess was true, and the log data in ftp.LastError was clean. Not sure under what case this might happen. Looking into the doc's there no case for a -1. Thoughts?

private async Task<bool> _WaitTaskAsync(Chilkat.Ftp2 ftp, Chilkat.Task task, CancellationToken ct)
{
  if (task == null)
  {
    throw new Exception(ftp.LastErrorText);
  }
  if (!task.Run())
  {
    throw new Exception(ftp.LastErrorText);
  }
  while (!task.Finished)
  {
    if (ct.IsCancellationRequested)
    {
      task.Cancel();
      break;
    }
    //Sleep 100 ms.
    await Task.Delay(100, ct);
  }
  await Task.Delay(100, ct);
  if (!ct.IsCancellationRequested)
  {
    if (task.StatusInt != 7)
    {
      throw new Exception(ftp.LastErrorText);
    }
    if (!task.TaskSuccess)
    {
      throw new Exception(ftp.LastErrorText);
    }
    return true;
  }
  return false;
}

{"ChilkatLog:
  GetDirCount:
    DllDate: May 20 2016
    ChilkatVersion: 9.5.0.58
    UnlockPrefix: 
    Architecture: Little Endian; 64-bit
    Language: .NET 4.5 / x64
    VerboseLogging: 0
    listPattern: *
    fetchDirListing:
      pattern: *
      supportsMLSD: 0
      fetchDirListing2:
        setupDataConnection:
          passive transfer mode
          setupPassiveDataSocket:
            sendCommand:
              sendingCommand: PASV
            --sendCommand
            readCommandResponse:
              replyLineQP: 227 Entering Passive Mode ().
            --readCommandResponse
            dataConnect:
              hostname: 
              port: 60801
              socketOptions:
                SO_SNDBUF: 262144
                SO_RCVBUF: 4194304
                TCP_NODELAY: 0
                SO_KEEPALIVE: 0
              --socketOptions
              dataConnectSuccess: 1
            --dataConnect
          --setupPassiveDataSocket
        --setupDataConnection
        sendCommand:
          sendingCommand: LIST
        --sendCommand
        readCommandResponse:
          replyLineQP: 150 Here comes the directory listing.
        --readCommandResponse
        readFtpDataChannel:
          dirListSize: 158
        --readFtpDataChannel
        Unix/Linux directory listing
        readCommandResponse:
          replyLineQP: 226 Directory send OK.
        --readCommandResponse
        ListTimeMS: 359
      --fetchDirListing2
    --fetchDirListing
    N: 2
    Success.
  --GetDirCount
--ChilkatLog
"}

asked Jun 08 at 13:34

GarySmith's gravatar image

GarySmith
11

edited Jun 08 at 13:34


I know this is confusing.... but the TaskSuccess does not apply to all methods. Here's the description in the reference documentation:

This is the value of the LastMethodSuccess property of the underlying task object. This property is only valid for those methods where the LastMethodSuccess property would be valid had the method been called synchronously.

The LastMethodSuccess property applies to any Chilkat method that returns a new object, a string, a byte array (or equivalent such as a Variant for the ActiveX), or a boolean that indicates success/failure.

The GetDirCount method returns an integer, where -1 indicates failure. It is for this reason that the LastMethodSuccess and TaskSuccess properties do not apply.

If an integer-returning method such as GetDirCount is called asynchronously, then when the task completes, the app should call task.GetResultInt to get the integer return value.

Instead of

    if (!task.TaskSuccess)
    {
      throw new Exception(ftp.LastErrorText);
    }
Your code should do this:
    if (task.GetResultInt < 0)
    {
      throw new Exception(ftp.LastErrorText);
    }

link

answered Jun 08 at 17:49

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

That makes sense. I'll need to rework my async method to handle this case. I'm trying to wiggle Ftp2 in place of an existing FTP library that had issues. I just need to bite the bullet and start implementing the code directly. The overall library is all async and called via web services so that complicates some things.

(Jun 08 at 21:36) GarySmith
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:

×131
×9

Asked: Jun 08 at 13:34

Seen: 373 times

Last updated: Jun 08 at 21:36

powered by OSQA