/// <summary> /// Will fire all events according to the queued messages /// </summary> public void Work() { if (Stopped) { throw new InvalidOperationException($"{nameof(EasySocket)} was stopped"); } SocketAsyncEventArgs result; while (!_acceptedSockets.IsEmpty) { if (_acceptedSockets.TryDequeue(out result)) { OnAccepted?.Invoke(Socket, result); } } while (!_receivedData.IsEmpty) { if (_receivedData.TryDequeue(out result)) { OnReceived?.Invoke(Socket, result); } } while (!_receivedFromData.IsEmpty) { if (_receivedFromData.TryDequeue(out result)) { OnReceivedFrom?.Invoke(Socket, result); } } while (!_receivedMessageFromData.IsEmpty) { if (_receivedMessageFromData.TryDequeue(out result)) { OnReceivedMessageFrom?.Invoke(Socket, result); } } while (!_sendComplete.IsEmpty) { if (_sendComplete.TryDequeue(out result)) { OnSent?.Invoke(Socket, result); } } while (!_sendToComplete.IsEmpty) { if (_sendToComplete.TryDequeue(out result)) { OnSentTo?.Invoke(Socket, result); } } }
private void OnSendToComplete(object sender, SocketAsyncEventArgs socketAsyncEventArgs) { Task.Run(() => OnSentTo?.Invoke(this, socketAsyncEventArgs)); }