private void StartTimer()
        {
            var dispatchSourceTimer = new DispatchSource.Timer(DispatchQueue.MainQueue);

            var delay  = 2 * NanosecondsInSecond;
            var leeway = 5 * NanosecondsInSecond;

            dispatchSourceTimer.SetTimer(DispatchTime.Now, delay, leeway);
            dispatchSourceTimer.SetRegistrationHandler(() => PrintResult("Timer registered"));
            dispatchSourceTimer.SetEventHandler(() => PrintResult("Timer tick"));
            dispatchSourceTimer.SetCancelHandler(() => PrintResult("Timer stopped"));

            dispatchSource = dispatchSourceTimer;
            dispatchSource.Resume();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            nonObservablePropertiesUpdateTimer.SetEventHandler(UpdateNonObservableProperties);
            nonObservablePropertiesUpdateTimer.SetTimer(DispatchTime.Now, 1000000, 0);
            nonObservablePropertiesUpdateTimer.Resume();

            var options = NSKeyValueObservingOptions.Initial | NSKeyValueObservingOptions.New;

            rateToken = Player.AddObserver("rate", options, RateChanged);
            timeControlStatusToken      = Player.AddObserver("timeControlStatus", options, timeControlStatusChanged);
            reasonForWaitingToPlayToken = Player.AddObserver("reasonForWaitingToPlay", options, ReasonForWaitingToPlayChanged);
            playbackLikelyToKeepUpToken = Player.AddObserver("currentItem.playbackLikelyToKeepUp", options, PlaybackLikelyToKeepUpChanged);
            loadedTimeRangesToken       = Player.AddObserver("currentItem.loadedTimeRanges", options, LoadedTimeRangesChanged);
            playbackBufferFullToken     = Player.AddObserver("currentItem.playbackBufferFull", options, PlaybackBufferFullChanged);
            playbackBufferEmptyToken    = Player.AddObserver("currentItem.playbackBufferEmpty", options, PlaybackBufferEmptyChanged);
        }
示例#3
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();
        }
示例#4
0
        public override async void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            await CheckAndRequestPermissionAsync(new Permissions.LocationAlways());

            _timer = new DispatchSource.Timer(DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Background));

            _timer.SetEventHandler(async() =>
            {
                var location = await Geolocation.GetLocationAsync(new GeolocationRequest()
                {
                    Timeout         = TimeSpan.FromSeconds(5),
                    DesiredAccuracy = GeolocationAccuracy.Best
                });

                System.Diagnostics.Debug.WriteLine($"{location?.Latitude}, {location?.Longitude}, {DateTime.Now}");
            });
        }