Exemplo n.º 1
0
        private void socket_Sent(object sender, SocketAsyncEventArgs e)
        {
            ThreadHelper.Sync(() =>
            {
                if (e.BytesTransferred > 0)
                {
                    // remove sent message
                    outbox.EndDequeue();

                    // start receiver loop (if needed)
                    if (isFirstReceive)
                    {
                        isFirstReceive = false;

                        StartReceive();
                    }

                    // if there is data to send - start another send
                    if (outbox.Count > 0)
                    {
                        StartSend();
                    }
                }
                else
                {
                    // connection was closed; restore last message
                    outbox.CancelDequeue();
                }

                e.Dispose();
            });
        }