Exemple #1
0
        private void Recv()
        {
            Logger.Log("sock recv thread start...");
            while (!close && !interrupted)
            {
                try
                {
                    long interval = DateTime.Now.Ticks;

                    if (sock == null)
                    {
                        Logger.LogWarning("sock is null by not close");
                        break;
                    }
                    else if (!Connected)
                    {
                        Logger.LogWarning("sock disconnected by not close");
                        break;
                    }
                    else
                    {
                        OnRecv();
                    }

                    interval = System.DateTime.Now.Ticks - interval;
                    int sleep = 10 - (int)SysUtil.TickToMilliSec(interval);
                    if (sleep > 0)
                    {
                        Thread.Sleep(sleep);
                    }
                }
                catch (System.Exception ex)
                {
                    if (!(ex is System.Threading.ThreadAbortException))
                    {
                        Logger.LogError(ex);
                    }
                    else
                    {
                        Logger.Log("recv thread abort");
                    }
                    interrupted = true;
                }
            }
            interrupted = true;
            Logger.Log("sock recv thread end normally");
        }