private void VerifyLastMessage()
        {
            TimeSpan current = DateTime.Now - lastMessageTime;

            if (current > toleranceTime)
            {
                disconnectEvent?.Invoke(true, new EventArgs());
            }
        }
        private void ReadConnection()
        {
            try
            {
                while (run.Run)
                {
                    string msg = conn.Read();
                    if (!string.IsNullOrEmpty(msg))
                    {
                        handle.Arrived(msg);
                    }
                }

                logger.LogInformation("thread read end: " + this.connectionId);
            }
            catch (Exception e)
            {
                logger.LogError("Error read Crystal Connection", e);
                disconnectEvent?.Invoke(false, new EventArgs());
            }
        }
Example #3
0
        private void Write()
        {
            string msg = null;

            try
            {
                while (run.Run)
                {
                    msg = queue.Take();
                    conn.Write(msg);
                }

                logger.LogInformation("thread write end");
            }catch (Exception e)
            {
                if (!string.IsNullOrEmpty(msg))
                {
                    queue.Add(msg);
                }

                logger.LogError("crystal writer error", e);
                disconnectEvent?.Invoke(false, new EventArgs());
            }
        }