/// <summary> /// Sends a message to the connection. /// </summary> /// <remarks> /// <note type="note">Messages sent to a connection are automatically encrypted for the receiver /// prior to sending. /// </note> /// </remarks> /// <param name="message">The message to send.</param> /// <returns>An asynchronous <see cref="Task"/> completes once the operation completes.</returns> public Task SendAsync(string message) { var taskCompletionSource = new TaskCompletionSource <bool>(); var commandHandle = PendingCommands.Add(taskCompletionSource); var result = IndyNativeMethods.indy_agent_send( commandHandle, Handle, message, CallbackHelper.TaskCompletingNoValueCallback ); CallbackHelper.CheckResult(result); return(taskCompletionSource.Task); }
/// <summary> /// Sends a message to a connection. /// </summary> /// <param name="connection">The connection to send the message to.</param> /// <param name="message">The message to send.</param> /// <returns>An asynchronous task that returns no value.</returns> private static Task AgentSendAsync(Connection connection, string message) { var taskCompletionSource = new TaskCompletionSource <bool>(); var commandHandle = AddTaskCompletionSource(taskCompletionSource); var result = IndyNativeMethods.indy_agent_send( commandHandle, connection.Handle, message, _noValueCallback ); CheckResult(result); return(taskCompletionSource.Task); }