"An asynchronous socket operation is now being used with this SocketAsyncEventArgs instance"
Found that a lot of people in the use of SocketAsyncEventArgs for high-performance communication development encountered this problem, but there is no specific solution on the network, so record sharing under my processing method
First, this problem typically occurs when an access connection, and data is sent, received
1. This exception is thrown when the connection is received, it is necessary to synchronize the receive connection, wait with Semaphor
2. The core of using SocketAsyncEventArgs is to implement object reuse, reduce the allocation and recycling of objects to improve program performance. Usually using a stack or queue to manage asynchronous objects, I'm using a stack
Stack pools are LIFO, the reception of multithreaded data, the sending and the pop of objects, the push is confusing (so it should be better to use a queue), so you need to implement synchronization between them
The synchronous implementation is done by using lock when a connection is broken to ensure that the operation of the asynchronous object is synchronized, because only the pop and push of the asynchronous object are available when the connection is broken.
The above is only my personal solution to this problem of thinking and methods, specific analysis, hope can help you
This article is from the "Xiao Universe" blog, make sure to keep this source http://5460095.blog.51cto.com/5450095/1758465
"You are now using this SocketAsyncEventArgs instance for asynchronous socket operations" processing