Archived Forum Post

Index of archived forum posts

Question:

Task.StatusInt = -1

Jun 08 '16 at 21:36

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
"}

Answer

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);
    }