public IAsyncResult BeginAccept(AsyncCallback callback, object state) { AsyncAcceptRegistration asyncRegistration = new AsyncAcceptRegistration(this, callback, state); lock (_acceptRegistrations) _acceptRegistrations.Add(asyncRegistration); return(null); }
static private void UDTThreadProcessing() { try { while (Thread.CurrentThread.IsAlive) { //---- Accept for (int index = _acceptRegistrations.Count - 1; index > -1; index--) { Monitor.Enter(_acceptRegistrations); AsyncAcceptRegistration registration = _acceptRegistrations[index]; Monitor.Exit(_acceptRegistrations); if (registration.Socket.IsOnAccept) { // Stop "BeginAccept" lock (_acceptRegistrations) _acceptRegistrations.RemoveAt(index); // Queue it for the call back _processor.AddCommand(registration); } } //---- Receive for (int index = _receiveRegistrations.Count - 1; index > -1; index--) { Monitor.Enter(_receiveRegistrations); AsyncReceiveRegistration registration = _receiveRegistrations[index]; Monitor.Exit(_receiveRegistrations); if (!registration.Socket.Connected || registration.Socket.IsOnRead) { // Stop "BeginReceive" lock (_receiveRegistrations) _receiveRegistrations.RemoveAt(index); // Queue it for the call back _processor.AddCommand(registration); } } //---- Like "Select" Wait for an event or 1 millisecond API_WaitForEvent(); } } catch (ThreadInterruptedException) { } }
public IAsyncResult BeginAccept(AsyncCallback callback, object state) { AsyncAcceptRegistration asyncRegistration = new AsyncAcceptRegistration(this, callback, state); lock (_acceptRegistrations) _acceptRegistrations.Add(asyncRegistration); return null; }