Listening for several connections in an async method Is there a better way to structure a method that returns a task that queues several inbound socket connections?

    public Task Start(CancellationToken token)
    {
        return Task.Run(
            () =&gt;
            {
                var acceptCount = new SemaphoreSlim(10);
                while (!token.IsCancellationRequested)
                {
                    acceptCount.Wait(token);
                    if (token.IsCancellationRequested)
                        break;

                    var args = new SocketAsyncEventArgs();
                    args.UserToken = acceptCount;
                    args.Completed += AcceptInbound;
                    if (!this.socket.AcceptAsync(args))
                        AcceptInbound(this.socket, args);

                }
            }, 
            token);
    }
    private void AcceptInbound(object sender, SocketAsyncEventArgs e)
    {
        ((SemaphoreSlim)e.UserToken).Release();
        Socket connectedClient = e.AcceptSocket;
    }
I think Task.Factory.FromAsync is what you are looking for...

public async Task Start(CancellationToken token)
{
     while (!token.IsCancellationRequested)
     {
         Socket connectedClient = await AcceptAsync(this.socket).ConfigureAwait(false);
         ...
     }
}

public static Task&lt;Socket&gt; AcceptAsync(Socket socket)
{
     return Task.Factory.FromAsync&lt;Socket&gt;(socket.BeginAccept, socket.EndAccept, null);
}