Esempio n. 1
0
        void StartTimer(PackageTimerData data)
        {
            var stateTimer = new Timer(HandleTimer,
                                       data, _Timeout, Timeout.Infinite);

            data._Timer = stateTimer;
        }
Esempio n. 2
0
        public void RemovePackage(char cmd)
        {
            //全变成小写
            cmd = Char.ToLower(cmd);

            if (_WaitingRspDic.ContainsKey(cmd))
            {
                PackageTimerData ptdata = _WaitingRspDic[cmd];

                ptdata._Timer.Dispose();


                Console.WriteLine(string.Format("QueueNeedRsp RemoveKey: {0} count: {1}", cmd, ptdata._Count));
                _WaitingRspDic.Remove(cmd);
            }
            else
            {
                Console.WriteLine("QueueNeedRsp Key Not Exsit:" + cmd);
            }
        }
Esempio n. 3
0
        public void AddPackage(Package pkg)
        {
            char cmd = pkg._Cmd;


            //全变成小写
            cmd = Char.ToLower(cmd);

            if (_WaitingRspDic.ContainsKey(cmd))
            {
                Console.WriteLine("QueueNeedRsp Key Exsit:" + cmd);
            }
            else
            {
                PackageTimerData ptdata = new PackageTimerData();
                ptdata._Package = pkg;

                _WaitingRspDic.Add(cmd, ptdata);

                StartTimer(ptdata);
            }
        }
Esempio n. 4
0
        private void HandleTimer(object data)
        {
            PackageTimerData ptdata = data as PackageTimerData;

            ptdata._Count++;

            if (ptdata._Count > _MaxRetry && _WaitingRspDic.ContainsKey(ptdata._Package._Cmd))
            {
                RemovePackage(ptdata._Package._Cmd);

                Console.WriteLine(string.Format("QueueNeedRsp Retry Failed: {0} IP: {1}", ptdata._Package._Cmd, ptdata._Package._SendTo.Address));
            }
            else
            {
                Console.WriteLine(string.Format("QueueNeedRsp Retry Cmd: {0} count: {1}", ptdata._Package._Cmd, ptdata._Count));

                Program.SendToTerminal(ptdata._Package, false);


                var stateTimer = new Timer(HandleTimer,
                                           data, _Timeout, Timeout.Infinite);
                ptdata._Timer = stateTimer;
            }
        }