Exemplo n.º 1
0
        /// <summary>
        /// Invokes the relevant <see cref="PacketReceivedHandler{P}"/> for each packet in the <see cref="receivedPackets"/> queue.
        /// </summary>
        private void InvokeWork()
        {
            try
            {
                while (true)
                {
                    //Wait till we receive a packet.
                    packetAvailableEvent.WaitOne();

                    while (receivedPackets.Count > 0)
                    {
                        Packet toDelegate = null;
                        if (!receivedPackets.TryDequeue(out toDelegate))
                        {
                            continue;
                        }

                        toDelegate.BeforeReceive();
                        HandleDefaultPackets(toDelegate);
                    }
                }
            }
            catch (ThreadAbortException) { return; }
            catch (Exception) { }

            CloseHandler(CloseReason.InvokePacketThreadException);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Invokes the relevant <see cref="PacketReceivedHandler{P}"/> for each packet in the <see cref="receivedPackets"/> queue.
        /// </summary>
        private void InvokeWork()
        {
            try
            {
                while (true)
                {
                    //Wait till we receive a packet.
                    packetAvailableEvent.WaitOne();

                    while (receivedPackets.Count > 0)
                    {
                        Packet toDelegate = null;
                        if (!receivedPackets.TryDequeue(out toDelegate))
                        {
                            continue;
                        }

                        toDelegate.BeforeReceive();
                        HandleDefaultPackets(toDelegate);
                    }
                }
            }
            catch (ThreadAbortException) { return; }
#if !NET46
            catch (ObjectDisposedException) { return; }
#endif
            catch (Exception exception)
            {
                Logger.Log($"Delegating packet to subscribers.", exception, LogLevel.Exception);
            }

            CloseHandler(CloseReason.InvokePacketThreadException);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Invokes the relevant <see cref="PacketReceivedHandler{P}"/> for each packet in the <see cref="receivedPackets"/> queue.
        /// </summary>
        private void InvokeWork()
        {
            try
            {
                while (true)
                {
                    WaitHandle.WaitAny(new WaitHandle[] { packetAvailableEvent, threadCancellationTokenSource.Token.WaitHandle });

                    // exit the endless loop via an exception if the network threads have been signaled to abort.
                    threadCancellationTokenSource.Token.ThrowIfCancellationRequested();

                    while (receivedPackets.Count > 0)
                    {
                        Packet toDelegate = null;
                        if (!receivedPackets.TryDequeue(out toDelegate))
                        {
                            continue;
                        }

                        toDelegate.BeforeReceive();
                        HandleDefaultPackets(toDelegate);
                    }
                }
            }
            catch (OperationCanceledException) { return; }
            catch (Exception exception)
            {
                Logger.Log($"Delegating packet to subscribers.", exception, LogLevel.Exception);
            }

            CloseHandler(CloseReason.InvokePacketThreadException);
        }
Exemplo n.º 4
0
        /// <summary>
        /// This thread checks for new packets in the queue and delegates them
        /// to the desired delegates, if given.
        /// </summary>
        private void InvokeWork()
        {
            try
            {
                while (IsAlive)
                {
                    while (receivedPackets.Count > 0)
                    {
                        Packet toDelegate = null;
                        if (!receivedPackets.TryDequeue(out toDelegate))
                        {
                            continue;
                        }

                        toDelegate.BeforeReceive();
                        HandleDefaultPackets(toDelegate);
                    }

                    Thread.Sleep(CPU_SAVE);
                }
            } catch { }
        }