コード例 #1
0
        /**********************************************************************
         *********************************************************************/
        public static void MyTimer(int seqnum, int c)
        {
            int counter = c;

            String counterText = "";
            var    ccl_LNumber = new CCLabel(counterText, "Arial", 20);

            if (!stopEverything)
            {
                //draw counter label in respective rectangle
                float a    = 28 - seqnum;
                float yPos = 15 + (a * 65);
                counterText = "" + counter;

                ccl_LNumber.Position = new CCPoint(60, yPos + 25);
                ccl_LNumber.Color    = CCColor3B.Red;
                layer.AddChild(ccl_LNumber);
            }

            Device.StartTimer(TimeSpan.FromSeconds(1), () =>
            {
                if (stopEverything)
                {
                    layer.Dispose();
                    return(false);
                }

                // update counter label- but only if the user didn't click pause
                if (!animationIsPaused)
                {
                    counter++;
                }
                if (!stopEverything)
                {
                    counterText      = "" + counter;
                    ccl_LNumber.Text = counterText;
                }

                if (stopEverything || counter == timeouttime)
                {
                    layer.RemoveChild(ccl_LNumber);



                    //resend pending ACK after timeout if seqnum is in list
                    if (pendingAck.Any() && pendingAck.Contains(seqnum) && !stopEverything)
                    {
                        SendPackageAt(seqnum);
                        MyTimer(seqnum, 0);
                    }
                    return(false);    //False = Stop the timer
                }
                else
                {
                    return(true);
                }                         // True = Repeat again
            });
        }