/// <summary> /// Closes a listener. /// </summary> /// <param name="listener">The listener to close.</param> /// <returns>An asynchronous task that returns no value.</returns> private static Task AgentCloseListenerAsync(Listener listener) { var taskCompletionSource = new TaskCompletionSource <bool>(); var commandHandle = AddTaskCompletionSource(taskCompletionSource); var result = IndyNativeMethods.indy_agent_close_listener( commandHandle, listener.Handle, _noValueCallback ); CheckResult(result); return(taskCompletionSource.Task); }
/// <summary> /// Closes the listener. /// </summary> /// <remarks> /// <para>When a listener is closed it stops listening for new incoming connections and /// all incoming <see cref="AgentConnection"/> instances accepted by the listener are also /// closed. /// </para> /// <para>Once closed a listener cannot be re-opened; a new listener instance must instead be /// created using the <see cref="ListenAsync(string)"/> static method. /// </para> /// </remarks> /// <returns>An asynchronous <see cref="Task"/> completes once the operation completes.</returns> public Task CloseAsync() { _requiresClose = false; var taskCompletionSource = new TaskCompletionSource <bool>(); var commandHandle = PendingCommands.Add(taskCompletionSource); var result = IndyNativeMethods.indy_agent_close_listener( commandHandle, Handle, CallbackHelper.TaskCompletingNoValueCallback ); CallbackHelper.CheckResult(result); GC.SuppressFinalize(this); return(taskCompletionSource.Task); }
/// <summary> /// Closes the listener. /// </summary> /// <remarks> /// <para>When a listener is closed it stops listening for new incoming connections and /// all incoming <see cref="AgentConnection"/> instances accepted by the listener are also /// closed. /// </para> /// <para>Once closed a listener cannot be re-opened; a new listener instance must instead be /// created using the <see cref="ListenAsync(string)"/> static method. /// </para> /// </remarks> /// <returns>An asynchronous <see cref="Task"/> completes once the operation completes.</returns> public Task CloseAsync() { if (_closeRequested) { return(Task.FromResult(true)); } var taskCompletionSource = new TaskCompletionSource <bool>(); var commandHandle = PendingCommands.Add(taskCompletionSource); var result = IndyNativeMethods.indy_agent_close_listener( commandHandle, Handle, CallbackHelper.TaskCompletingNoValueCallback ); CallbackHelper.CheckResult(result); _closeRequested = true; GC.SuppressFinalize(this); return(taskCompletionSource.Task); }