Esempio n. 1
0
        public void SendAsync(byte[] Data, Action Callback = null)
        {
            var DataCopy = new byte[Data.Length];

            Array.Copy(Data, DataCopy, Data.Length);

            var BuffersCopy = new List <ArraySegment <byte> >()
            {
                new ArraySegment <byte>(DataCopy)
            };

            AsyncQueue.Add(() =>
            {
                try
                {
                    NativeSocket.BeginSend(BuffersCopy, SocketFlags.None, (IAsyncResult) =>
                    {
                        SocketError SocketError;
                        NativeSocket.EndSend(IAsyncResult, out SocketError);
                        Core.EnqueueTask(() =>
                        {
                            if (Callback != null)
                            {
                                Callback();
                            }
                            AsyncQueue.Next();
                        });
                    }, null);
                }
                catch (SocketException SocketException)
                {
                    SocketExceptionThrown(SocketException);
                }
            });
        }