Ejemplo n.º 1
0
        //private void DoTick()
        //{
        //    Thread.Sleep(TickLength); //Five seconds

        //    //At the end of the tick...
        //    LastTick = DateTime.UtcNow;
        //}

        private void TimerTask(object StateObj)
        {
            StateObjClass State = (StateObjClass)StateObj;

            // Use the interlocked class to increment the counter variable.
            System.Threading.Interlocked.Increment(ref State.SomeValue);
            if (State.TimerCanceled)
            // Dispose Requested.
            {
                State.TimerReference.Dispose();
            }

            // Do Stuff

            cuskObjectDatabase.ForEachEntity(e => e.DoMoves());

            Thread.Sleep(TickLength);
        }
Ejemplo n.º 2
0
        public void RunTick()
        {
            DateTime StartOfTick = DateTime.UtcNow;


            StateObjClass StateObj = new StateObjClass();

            StateObj.TimerCanceled = false;
            StateObj.SomeValue     = 1;
            //System.Threading.TimerCallback TimerDelegate =
            //    new System.Threading.TimerCallback(TimerTask);


            //// Create a timer that calls a procedure every 2 seconds.
            //// Note: There is no Start method; the timer starts running as soon as
            //// the instance is created.
            //System.Threading.Timer TimerItem =
            //    new System.Threading.Timer(TimerDelegate, StateObj, 2000, 2000);

            //// Save a reference for Dispose.
            //StateObj.TimerReference = TimerItem;

            //// Run for ten loops.
            //while (StateObj.SomeValue < 10)
            //{
            //    // Wait one second.
            //    System.Threading.Thread.Sleep(1000);
            //}

            //// Request Dispose of the timer object.
            //StateObj.TimerCanceled = true;

            TimerTask(StateObj);

            EndOfTick = DateTime.UtcNow;
            TimeSpan ActualTickLength;

            ActualTickLength = EndOfTick - StartOfTick;
            TickMSLength     = (int)ActualTickLength.TotalMilliseconds;
        }