ReceiveAsync performance versus BeginReceive

I am currently programming a client application, and I am wondering if I should use the Socket class of the ReceiveAsync or BeginReceive class. I have used the latter so far, however, I have found that it seems to be strengthening the processor a bit. This is what my intake cycle looks like:

private void socket_ReceiveCallback(IAsyncResult result_)
{
    // does nothing else at the moment
    socket.EndReceive(result_);
    byte[] buffer = (byte[])result_.AsyncState;

    // receive new packet
    byte[] newBuffer = new byte[1024];
    socket.BeginReceive(newBuffer, 0, newBuffer.Length, SocketFlags.None, 
                        socket_ReceiveFallback, newBuffer);
}

Now I was wondering if I was not doing something wrong here, since other applications that communicate almost do not affect the processor. And also I am wondering if I would be better off using SocketAsyncEventArgs and ReceiveAsync.

So here are my questions:

Why does my cycle load the processor so much? Should I use SocketAsyncEventArgs and ReceiveAsync instead of BeginReceive?

+5
source share
2

loopback-. , 30% . , , - . , . 128 , IO .

, , - .

, -, .

+5
+1

All Articles