Exemple #1
0
        public override void ViewDidUnload()
        {
            base.ViewDidUnload();

            _timer?.SetEventHandler(null);
            _timer?.Cancel();

            /*
             * If the timer is suspended, calling cancel without resuming
             * triggers a crash. This is documented here https://forums.developer.apple.com/thread/15902
             */
            if (!timerRunning ?? false)
            {
                _timer?.Resume();
            }

            _timer?.Dispose();
        }
Exemple #2
0
        public DispatchTimer(long delay, DispatchQueue queue, TimerHandler block)
        {
            this.timerBlock = block;
            this.queue      = queue;
            this.delay      = delay;
            this.source     = new DispatchSource.Timer(queue);

            base.Init();

            Action wrapper = () =>
            {
                if (!source.IsCanceled)
                {
                    source.Cancel();
                    timerBlock(this);
                }
            };

            wrappedBlock = wrapper;
        }