locked
AsyncActionCompletedHandler status

    Question

  • Hi,

    I add a  AsyncActionCompletedHandler to be notified when StreamScoket.ConnectAsync operation completes.

    MSD documentation for this handler is

    public delegate void AsyncActionCompletedHandler(
      IAsyncAction asyncInfo, 
      AsyncStatus asyncStatus
    )

    IAsyncAction also has an AsyncStatus member Status, is this the same as the AsyncStatus passed to the handler or they reflect different things?

    If the operation fails will asyncInfo->ErrorCode.Value contain the SocketErrorStatus?

    Wednesday, May 09, 2012 6:41 PM

Answers

All replies

  • Hello,

     

    AsyncStatus only return the previous async operator status like Canceled, Completed, Error, Started.

     

    If your ConnectAsync failed with error. The asyncStatus return 3, and it is not the SocketErrorStatus.

     

    The SocketErrorStatus error you should use SocketError.GetStatus  to get is this is static function.

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.sockets.socketerror.getstatus.aspx

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Jesse Jiang Thursday, May 17, 2012 8:06 AM
    • Marked as answer by pepone.onrez Thursday, May 17, 2012 3:34 PM
    Thursday, May 10, 2012 8:47 AM
  • To be sure i understand it correctly, could i do something like this
    AsyncOperationWithProgressCompletedHandler<IBuffer^, uint32> readInfo = ...;
    
    readInfo->Completed = ref new AsyncOperationWithProgressCompletedHandler<IBuffer^, uint32>
        ([=](IAsyncOperationWithProgress<IBuffer^,uint32>^ info, AsyncStatus status)
                {
                    if(info->Status == AsyncStatus::Error)
                    {
                        int errorCode = SocketError::GetStatus();
                        // handle socket error.
                    }
                    else if(info->Status == AsyncStatus::Canceled)
                    {
                        // operation was canceled.
                    }
                    else
                    {
                        // operation success
                        IBuffer^ b = info->GetResults();
                    }
                });

    Thursday, May 10, 2012 3:18 PM
  • Hello,

    You should use asyncStatus==AsyncStatus::Error to get the error result.

    if(asyncStatus==AsyncStatus::Error)
                {
                    try
                    {
                        int res= info->GetResults();

                    }catch(Exception^ ex)
                    {
                     
                    }
                }

    You can also use try-catch block in the task.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, May 17, 2012 8:06 AM