Example #1
0
        void SendTask()
        {
            while (true)
            {

                if (sendQueue.Count == 0 && currentSendPkg == null)
                {
                    lock (this.SendQueueLock)
                    {
                        System.Threading.Monitor.Wait(this.SendQueueLock);

                    }
                }
                if (sendQueue.Count > 0)
                {
                    lock(this.sendQueue)
                    currentSendPkg = sendQueue.Dequeue();

                    while (currentSendPkg.SendCnt < MAX_TRY_CNT)
                    {
                        currentSendPkg.SendCnt++;
                        this.SendBytes(currentSendPkg.ToCmdBytes());
                        //if (currentSendPkg.ReturnCmd != 0xff)
                        //{
                            lock (WaitRespLock)
                            {
                                if (System.Threading.Monitor.Wait(this.WaitRespLock, TIMEOUT_MSEC))

                                    break;

                                // here means timeout

                            }

                        //}
                        //else  // not  a request

                        //    break;

                    }// while

                    if (currentSendPkg.SendCnt < MAX_TRY_CNT)
                    {
                        if (currentSendPkg.ReturnCmd != 0xff)
                            currentSendPkg.NotifyCompleted();
                        else
                        {
                            if ((currentSendPkg.ReturnPackage as CoordinatorAck).IsSucess)
                                currentSendPkg.NotifyCompleted();
                            else
                                currentSendPkg.NotifyFail();
                        }

                    }
                    else
                    {
                        currentSendPkg.NotifyFail();

                    }
                    currentSendPkg = null;

                } //if

            }
        }
Example #2
0
        public void SendPackage(CmdBasePackage pkg)
        {
            lock (this.sendQueue)
            {
                this.sendQueue.Enqueue(pkg);
            }
            lock (SendQueueLock)
            {
                System.Threading.Monitor.Pulse(SendQueueLock);
            }

               // com.fl
        }