1

I'm going through the example code in https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.socketasynceventargs?redirectedfrom=MSDN&view=netframework-4.8 to understand it and get it working, however when i copied it over to try it out, under the Init() function

readWriteEventArg.UserToken = new AsyncUserToken();

the AsyncUserToken(); type or namespace cannot be found. I've created classes for the SetBuffer(Byte[], Int32, Int32) method and the SocketAsyncEventArgs constructor which the SocketAsyncEventArgs class both uses, but am stuck on finding this AsyncUserToken();

  • 2
    Possible duplicate of [AsyncUserToken class is missing in SocketAsyncEventArgs sample: How to make the sample works?](https://stackoverflow.com/questions/15738062/asyncusertoken-class-is-missing-in-socketasynceventargs-sample-how-to-make-the) – Progman Oct 20 '19 at 09:39

1 Answers1

1

I've found the missing class in the samples repository.

Here it is:

class AsyncUserToken
{
    Socket m_socket;

    public AsyncUserToken() : this(null) { }

    public AsyncUserToken(Socket socket)
    {
        m_socket = socket;
    }

    public Socket Socket
    {
        get { return m_socket; }
        set { m_socket = value; }
    }

}

I've also opened an issue in the dotnet-api-docs repo.

Youssef13
  • 3,836
  • 3
  • 24
  • 41