Пример #1
0
 public void Disconect()
 => OnDisconect?.Invoke(this, null);
Пример #2
0
        private void runSender()
        {
            while (this.m_isOpen && (m_port >= 0))
            {
                try
                {
                    bool flag = false;

                    for (int i = 0; i < connections.Count; i++)
                    {
                        if (connections[i].CallbackThread != null)
                        {
                            try
                            {
                                connections[i].CallbackThread = null;

                                lock (activeThreadsLock)
                                {
                                    activeThreads--;
                                }
                            }
                            catch (Exception ex)
                            {
                                OnError?.Invoke(this, ex);
                            }
                        }

                        if (this.connections[i].CallbackThread == null)
                        {
                            if (this.connections[i].connected() && ((connections[i].LastVerifyTime.AddMilliseconds((double)m_verifyConnectionInterval) > DateTime.UtcNow) || this.connections[i].verifyConnected()))
                            {
                                flag = flag || processConnection(connections[i]);
                            }
                            else
                            {
                                lock (connections)
                                {
                                    OnDisconect?.Invoke(connections[i]);

                                    connections.RemoveAt(i);
                                    i--;
                                }
                            }
                        }
                    }

                    if (flag)
                    {
                        continue;
                    }

                    Thread.Yield();

                    lock (this.sem)
                    {
                        foreach (TcpServersConnection connection in connections)
                        {
                            if (connection.hasMoreWork())
                            {
                                flag = true;
                                goto Label_0198;
                            }
                        }
                    }

Label_0198:
                    if (!flag)
                    {
                        waiting = true;
                        sem.Wait(m_idleTime);
                        waiting = false;
                    }

                    continue;
                }
                catch (ThreadInterruptedException)
                {
                    continue;
                }
                catch (Exception exception)
                {
                    if (m_isOpen && (OnError != null))
                    {
                        OnError(this, exception);
                    }

                    continue;
                }
            }
        }