Forum Xamarin.Forms

Detect idle screen

Blade4771Blade4771 USMember ✭✭

Hello,
I'm wondering when my application is inactive, say I want when spending 1 minute without using the User, can display a screen with several images, for example a random banner. But so far without success
can anybody help me?

My thread

  public class Waiter: Thread
    {
        private static string TAG = "Waiter";
        private long _lastUsed;
        private long _period;
        public bool stop;

        private DateTime _last;
        public Waiter (long period)
        {
            this._period = period;

        }

        public override void Run ()
        {
            long idle = 0;
            this.Touch ();
            do {

                TimeSpan span = DateTime.Now - _last;
                idle = (long)span.TotalMilliseconds;
                Console.WriteLine ("Application is idle for " + idle + " ms");
                try {

                    //Thread.Sleep (5000); 
                } catch {
                    Console.WriteLine ("Waiter interrupted!");
                }
                if (idle > _period) {
                    idle = 0;


                }
            } while (!stop);
            Console.WriteLine ("Finishing Waiter thread");
        }

        [MethodImpl (MethodImplOptions.Synchronized)]
        public  void Touch ()
        {
            //_lastUsed = DateTime.Now.Millisecond;
            _last = DateTime.Now;
        }

        [MethodImpl (MethodImplOptions.Synchronized)]
        public void ForceInterrupt ()
        {
            this.Interrupt ();
        }

        [MethodImpl (MethodImplOptions.Synchronized)]
        public new void Stop ()
        {
            stop = true;
        }

        [MethodImpl (MethodImplOptions.Synchronized)]
        public void SetPeriod(long period)
        {
            this._period = period;
        }

    }
}

Answers

Sign In or Register to comment.