Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot choose method from group in Task.FromAsync method

I have the following function

public static Task<int> SendTaskAsync(this Socket socket, byte[] buffer, int offset, int size, SocketFlags flags)
{
    AsyncCallback nullOp = (i) => { };
    IAsyncResult result = socket.BeginSend(buffer, offset, size, flags, nullOp, socket);
    // Use overload that takes an IAsyncResult directly
    return Task.Factory.FromAsync(result, socket.EndSend);
}

However I'm getting a

"Cannot choose method from group"

error on FromAsync. How should my code be? I'm pretty new to TAP

like image 259
Null Reference Avatar asked Mar 09 '26 02:03

Null Reference


1 Answers

Change this:

 return Task.Factory.FromAsync(result, socket.EndSend);

into this:

 return  Task<int>.Factory.FromAsync(result, socket.EndSend);

Edit:

As @cremor says, you can alternatively use:

 return Task.Factory.FromAsync<int>(result, socket.EndSend);
like image 121
Carlos Landeras Avatar answered Mar 10 '26 15:03

Carlos Landeras



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!