public void Bug2443()
        {
            var evt = new CountdownEvent(2);

            NSTimer timer = null;

            using (timer = NSTimer.CreateRepeatingTimer(0.1f, delegate {
                if (evt.Signal())
                {
                    timer.Invalidate();
                }
            })) {
                var thread = new Thread(() => {
                    NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Default);
                    NSRunLoop.Current.RunUntil(NSRunLoopMode.Default, NSDate.Now.AddSeconds(5));
                })
                {
                    IsBackground = true,
                };
                thread.Start();

                Assert.IsTrue(evt.Wait(TimeSpan.FromSeconds(5)), "Not signalled twice in 5s");
                thread.Join();
            }
        }
Exemple #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            /*
             * var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
             * path = System.IO.Path.Combine(path, "loop_stereo.aif"); // loop_mono.wav
             * if (!System.IO.File.Exists(path))
             *  throw new ArgumentException("file not found; " + path);*/

            var url = MonoTouch.CoreFoundation.CFUrl.FromFile("loop_stereo.aif");

            _player = new ExtAudioFilePlayer(url);

            // setting audio session
            _slider.ValueChanged  += new EventHandler(_slider_ValueChanged);
            _playButton.TouchDown += new EventHandler(_playButton_TouchDown);
            _stopButton.TouchDown += new EventHandler(_stopButton_TouchDown);

            _slider.MaxValue = _player.TotalFrames;

            _isTimerAvailable = true;
            _timer            = NSTimer.CreateRepeatingTimer(TimeSpan.FromMilliseconds(100),
                                                             delegate {
                if (_isTimerAvailable)
                {
                    long pos      = _player.CurrentPosition;
                    _slider.Value = pos;
                    //System.Diagnostics.Debug.WriteLine("CurPos: " + _player.CurrentPosition.ToString());
                }
            }
                                                             );
            NSRunLoop.Current.AddTimer(_timer, "NSDefaultRunLoopMode");
        }
Exemple #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var url = CFUrl.FromFile("loop_stereo.aif");

            _player = new ExtAudioBufferPlayer(url);

            // setting audio session
            _slider.ValueChanged += new EventHandler(_slider_ValueChanged);

            _slider.MaxValue = _player.TotalFrames;

            _isTimerAvailable = true;
            _timer            = NSTimer.CreateRepeatingTimer(TimeSpan.FromMilliseconds(100),
                                                             delegate
            {
                if (_isTimerAvailable)
                {
                    long pos               = _player.CurrentPosition;
                    _slider.Value          = pos;
                    _signalLevelLabel.Text = _player.SignalLevel.ToString("0.00E0");
                }
            }
                                                             );

            NSRunLoop.Current.AddTimer(_timer, NSRunLoopMode.Default);
        }
Exemple #4
0
        partial void exportToMovie(UIBarButtonItem sender)
        {
            exportProgressView.Hidden = false;

            Player.Pause();
            playPauseButton.Enabled  = false;
            transitionButton.Enabled = false;
            scrubber.Enabled         = false;
            exportButton.Enabled     = false;

            Editor.BuildCompositionObjects(false);

            var session = Editor.AssetExportSession(AVAssetExportSession.PresetMediumQuality);

            var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var filePath  = Path.Combine(documents, "..", "tmp", "ExportedProject.mov");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            session.OutputUrl      = NSUrl.FromFilename(filePath);
            session.OutputFileType = AVFileType.QuickTimeMovie;

            session.ExportAsynchronously(() => {
                DispatchQueue.MainQueue.DispatchAsync(() => {
                    exportCompleted(session);
                });
            });

            progressTimer = NSTimer.CreateRepeatingTimer(0.5, (d) => updateProgress(progressTimer));
            NSRunLoop.Current.AddTimer(progressTimer, NSRunLoopMode.Default);
        }
Exemple #5
0
        public void Bug17793()
        {
            var evt = new CountdownEvent(2);

            NSTimer timer = null;

            using (timer = NSTimer.CreateRepeatingTimer(0.1f, delegate {
                // This is the real test - not a timer test, but properly preserving VFP registers.
                // When bug #17793 manifests, this method is only called once instead of repeatedly.
                Func(0, 0, 0, 0, 0, 0, 0);
                if (evt.Signal())
                {
                    timer.Invalidate();
                }
            })) {
                var thread = new Thread(() => {
                    NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Default);
                    NSRunLoop.Current.RunUntil(NSRunLoopMode.Default, NSDate.Now.AddSeconds(5));
                })
                {
                    IsBackground = true,
                };
                thread.Start();

                Assert.IsTrue(evt.Wait(TimeSpan.FromSeconds(5)), "Not signalled twice in 5s");
                thread.Join();
            }
        }
Exemple #6
0
        public RootController()
            : base(new RootElement("Netstat"))
        {
            Settings = Settings.Instance;

            section = new Section();
            Root.Add(section);

            displayedEntries = new Dictionary <NetstatEntry, DateTime> ();

            RefreshRequested += (sender, e) => {
                Populate();
                ReloadComplete();
            };

            Settings.Modified += (sender, e) => InvokeOnMainThread(() => {
                displayedEntries.Clear();
                Populate();
            });

            timer = NSTimer.CreateRepeatingTimer(1.0, () => {
                if (View.Hidden || !Settings.AutoRefresh)
                {
                    return;
                }
                Populate();
            });
            NSRunLoop.Main.AddTimer(timer, NSRunLoopMode.Default);
        }
        partial void ExportToMovie(UIBarButtonItem sender)
        {
            this.exportProgressView.Hidden = false;

            this.player.Pause();
            this.playPauseButton.Enabled  = false;
            this.transitionButton.Enabled = false;
            this.scrubber.Enabled         = false;
            this.exportButton.Enabled     = false;

            this.editor.BuildCompositionObjectsForPlayback(false);

            // Get the export session from the editor
            var session = this.editor.AssetExportSessionWithPreset(AVAssetExportSession.PresetMediumQuality);

            var filePath = Path.Combine(Path.GetTempPath(), "ExportedProject.mov");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            // If a preset that is not compatible with AVFileTypeQuickTimeMovie is used, one can use -[AVAssetExportSession supportedFileTypes] to obtain a supported file type for the output file and UTTypeCreatePreferredIdentifierForTag to obtain an appropriate path extension for the output file type.
            session.OutputUrl      = NSUrl.FromFilename(filePath);
            session.OutputFileType = AVFileType.QuickTimeMovie;

            session.ExportAsynchronously(() => DispatchQueue.MainQueue.DispatchAsync(() => OnExportCompleted(session)));

            // Update progress view with export progress
            this.progressTimer = NSTimer.CreateRepeatingTimer(0.5, d => this.UpdateProgress(session));
            NSRunLoop.Current.AddTimer(this.progressTimer, NSRunLoopMode.Default);
        }
Exemple #8
0
        public override void LoadView()
        {
            base.LoadView();
            View.BackgroundColor = UIColor.LightGray;

            MakeButton("Show", () => {
                BTProgressHUD.Show();
                KillAfter();
            });

            MakeButton("Show Message", () => {
                BTProgressHUD.Show(status: "Processing your image");
                KillAfter();
            });

            MakeButton("Show Success", () => {
                BTProgressHUD.ShowSuccessWithStatus("Great success!");
            });

            MakeButton("Show Fail", () => {
                BTProgressHUD.ShowErrorWithStatus("Oh, thats bad");
            });

            MakeButton("Toast", () => {
                BTProgressHUD.ShowToast("Hello from the toast", showToastCentered: false);
            });


            MakeButton("Dismiss", () => {
                BTProgressHUD.Dismiss();
            });

            MakeButton("Progress", () => {
                progress = 0;
                BTProgressHUD.Show("Hello!", progress);
                if (timer != null)
                {
                    timer.Invalidate();
                }
                timer = NSTimer.CreateRepeatingTimer(0.5f, delegate {
                    progress += 0.1f;
                    if (progress > 1)
                    {
                        timer.Invalidate();
                        timer = null;
                        BTProgressHUD.Dismiss();
                    }
                    else
                    {
                        BTProgressHUD.Show("Hello!", progress);
                    }
                });
                NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Common);
            });

            MakeButton("Dismiss", () => {
                BTProgressHUD.Dismiss();
            });
        }
 public void Resume()
 {
     if (timeout != new TimeSpan(-1))
     {
         timer = NSTimer.CreateRepeatingTimer(timeout, view.RunIteration);
         NSRunLoop.Main.AddTimer(timer, NSRunLoopMode.Common);
     }
 }
        // Shared initialization code
        void Initialize()
        {
            var timerCount = 0;

            NSRunLoop.Current.AddTimer(NSTimer.CreateRepeatingTimer(TimeSpan.FromSeconds(0.1), () => {
                ModalCounter.StringValue = (timerCount++).ToString();
            }), NSRunLoopMode.Default);
        }
        /// <summary>
        /// Start the timer.
        /// </summary>
        public void Start()
        {
            DebugOutput("+++++ STARTING TIMER from thread: " + NSThread.Current.Handle + ", MAIN: " + NSThread.MainThread.Handle);
            var runLoop = NSRunLoop.Current;

            _timer = NSTimer.CreateRepeatingTimer(Interval, TimerTick);
            runLoop.AddTimer(_timer, NSRunLoop.NSRunLoopCommonModes);
        }
Exemple #12
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            NSTimer timer = NSTimer.CreateRepeatingTimer(3.0, delegate { gaugeView.Value = DataService.GetScore(); });

            NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Default);
        }
Exemple #13
0
        private void SetTimer()
        {
            timer = NSTimer.CreateRepeatingTimer(TimeSpan.FromSeconds(3), (obj) =>
            {
                ExceutTimer();
            });

            NSRunLoop.Current.AddTimer(timer, NSRunLoop.NSRunLoopCommonModes);
        }
Exemple #14
0
 void StartProgressTimer(TimeSpan duration)
 {
                 #if __UNIFIED__
     _progressTimer = NSTimer.CreateRepeatingTimer(duration, timer => UpdateProgress());
                 #else
     _progressTimer = NSTimer.CreateRepeatingTimer(duration, UpdateProgress);
                 #endif
     NSRunLoop.Current.AddTimer(_progressTimer, NSRunLoopMode.Common);
 }
Exemple #15
0
 public void StartWorker()
 {
     // starting timer
     if (null == _timer)
     {
         _timer = NSTimer.CreateRepeatingTimer(new TimeSpan(10000L * 50), delegate { worker(); });
         NSRunLoop.Current.AddTimer(_timer, "NSDefaultRunLoopMode");
     }
 }
Exemple #16
0
        protected void Init(float durationSeconds, AnimationUpdate updateDelegate, AnimationComplete completeDelegate)
        {
            // create our timer at 60hz
            AnimTimer = NSTimer.CreateRepeatingTimer(new TimeSpan(ANIMATION_TICK_FREQUENCY), new Action <NSTimer>(
                                                         delegate
            {
                // update our timer
                CurrentTime += ANIMATION_TICK_RATE;

                float percent = 0.00f;

                // check the style of animation they want
                switch (AnimStyle)
                {
                // linear is, well, linear.
                case Style.Linear:
                    {
                        percent = CurrentTime / durationSeconds;
                        break;
                    }


                // curve ease in starts SLOW and ends FAST
                case Style.CurveEaseIn:
                    {
                        float xPerc = CurrentTime / durationSeconds;
                        percent     = (float)System.Math.Pow(xPerc, 3.0f);
                        break;
                    }

                // curve ease out starts FAST and ends SLOW
                case Style.CurveEaseOut:
                    {
                        float xPerc = CurrentTime / durationSeconds;
                        percent     = (float)1 + (float)System.Math.Pow((xPerc - 1), 3.0f);
                        break;
                    }
                }

                // let the animation implementation do what it needs to
                AnimTick(System.Math.Min(percent, 1.00f), updateDelegate);

                // see if we're finished.
                if (CurrentTime >= durationSeconds)
                {
                    // we are, so notify the completion delegate
                    if (completeDelegate != null)
                    {
                        completeDelegate( );
                    }

                    // and kill the timer
                    AnimTimer.Invalidate( );
                }
            })
                                                     );
        }
Exemple #17
0
 void KillAfter(float timeout = 1)
 {
     if (timer != null)
     {
         timer.Invalidate();
     }
     timer = NSTimer.CreateRepeatingTimer(timeout, delegate {
         BTProgressHUD.Dismiss();
     });
     NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Common);
 }
Exemple #18
0
 static void StartBumpingGtkLoop()
 {
     if (bumperCount++ == 0)
     {
         var runLoop = NSRunLoop.Current;
         bumperTimer = NSTimer.CreateRepeatingTimer(0.1d, delegate {
             Gtk.Application.RunIteration(false);
         });
         runLoop.AddTimer(bumperTimer, NSRunLoop.NSRunLoopCommonModes);
     }
 }
Exemple #19
0
        public void StartTimer(TimeSpan interval, Func <Task <bool> > callback)
        {
            var timer = NSTimer.CreateRepeatingTimer(interval, async t =>
            {
                if (!(await callback()))
                {
                    t.Invalidate();
                }
            });

            NSRunLoop.Main.AddTimer(timer, NSRunLoopMode.Common);
        }
        public static void Initialize()
        {
            CoreLocationManager = new CLLocationManager();

            CoreLocationManager.StartUpdatingLocation();

            CoreLocationManager.UpdatedHeading  += HandleCoreLocationManagerUpdatedHeading;
            CoreLocationManager.UpdatedLocation += HandleCoreLocationManagerUpdatedLocation;

            UpdateLocationTimer = NSTimer.CreateRepeatingTimer(TimeSpan.FromMinutes(1), InitializeLocationUpdate);
            UpdateHeadingTimer  = NSTimer.CreateRepeatingTimer(TimeSpan.FromMinutes(1), InitializeHeadingUpdate);
        }
Exemple #21
0
            public void StartTimer(TimeSpan interval, Func <bool> callback)
            {
                NSTimer timer = NSTimer.CreateRepeatingTimer(interval, t =>
                {
                    if (!callback())
                    {
                        t.Invalidate();
                    }
                });

                NSRunLoop.Main.AddTimer(timer, NSRunLoopMode.Common);
            }
Exemple #22
0
        public void StartWorker()
        {
            if (WorkerTimer != null)
            {
                return;
            }


            WorkerTimer = NSTimer.CreateRepeatingTimer(new TimeSpan(1L), delegate {
                Worker();
            });
            NSRunLoop.Current.AddTimer(WorkerTimer, NSRunLoopMode.Default);
        }
        //private void BeepOrVibrate()
        //{
        //	SystemSound.FromFile("Sounds/beep.wav").PlayAlertSound();
        //}
        #endregion

        #region Public methods

        /*public void SetArrows(bool inRange, bool animated)
         * {
         *
         *
         *      // already showing green bars
         *      if (inRange && _isGreen) return;
         *
         *      // update flag
         *      _isGreen = inRange;
         *
         *      if (_isGreen)
         *      {
         *              _textCue.Text =  "Hold still for scanning";
         *              _otherView1 = _whiteTopArrow;
         *              _otherView2 = _whiteBottomArrow;
         *              _focusView1 = _greenTopArrow;
         *              _focusView2 = _greenBottomArrow;
         *      }
         *      else
         *      {
         *              _textCue.Text =  "Adjust barcode according to arrows";
         *              _focusView1 = _whiteTopArrow;
         *              _focusView2 = _whiteBottomArrow;
         *              _otherView1 = _greenTopArrow;
         *              _otherView2 = _greenBottomArrow;
         *      }
         *
         *      if (animated)
         *      {
         *              UIView.BeginAnimations("");
         *              UIView.SetAnimationDuration(0.15f);
         *              UIView.SetAnimationBeginsFromCurrentState(true);
         *      }
         *
         *      _focusView1.Alpha = 1;
         *      _focusView2.Alpha = 1;
         *
         *      _otherView1.Alpha = 0;
         *      _otherView2.Alpha = 0;
         *
         *      if (animated) UIView.CommitAnimations();
         * }*/

        public void StartWorker()
        {
            if (WorkerTimer != null)
            {
                return;
            }


            WorkerTimer = NSTimer.CreateRepeatingTimer(TimeSpan.FromMilliseconds(150), delegate {
                Worker();
            });
            NSRunLoop.Current.AddTimer(WorkerTimer, NSRunLoopMode.Default);
        }
        public void AddTimer()
        {
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 8, throwIfOtherPlatform: false);

            using (var tb = new CMTimebase(CMClock.HostTimeClock)) {
                var timer = NSTimer.CreateRepeatingTimer(CMTimebase.VeryLongTimeInterval, delegate { });

                Assert.AreEqual(CMTimebaseError.None, tb.AddTimer(timer, NSRunLoop.Current), "#1");
                Assert.AreEqual(CMTimebaseError.None, tb.SetTimerNextFireTime(timer, new CMTime(100, 2)), "#2");

                tb.RemoveTimer(timer);
            }
        }
Exemple #25
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // device init
            GraphicsDeviceOptions options = new GraphicsDeviceOptions(false, null, false, ResourceBindingModel.Improved);

#if DEBUG
            options.Debug = true;
#endif
            SwapchainSource      ss  = SwapchainSource.CreateNSView(this.View.Handle);
            SwapchainDescription scd = new SwapchainDescription(
                ss,
                width, height,
                PixelFormat.R32_Float,
                false);

            graphicsDevice = GraphicsDevice.CreateMetal(options);
            swapchain      = graphicsDevice.ResourceFactory.CreateSwapchain(ref scd);
            factory        = graphicsDevice.ResourceFactory;

            // resource init
            CreateSizeDependentResources();
            VertexPosition[] quadVertices =
            {
                new VertexPosition(new Vector3(-1,  1, 0)),
                new VertexPosition(new Vector3(1,   1, 0)),
                new VertexPosition(new Vector3(-1, -1, 0)),
                new VertexPosition(new Vector3(1,  -1, 0))
            };
            uint[] quadIndices = new uint[]
            {
                0,
                1,
                2,
                1,
                3,
                2
            };
            vertexBuffer = factory.CreateBuffer(new BufferDescription(4 * VertexPosition.SizeInBytes, BufferUsage.VertexBuffer));
            indexBuffer  = factory.CreateBuffer(new BufferDescription(6 * sizeof(uint), BufferUsage.IndexBuffer));
            graphicsDevice.UpdateBuffer(vertexBuffer, 0, quadVertices);
            graphicsDevice.UpdateBuffer(indexBuffer, 0, quadIndices);

            commandList = factory.CreateCommandList();

            viewLoaded = true;

            displayTimer = NSTimer.CreateRepeatingTimer(60.0 / 1000.0, Render);
            displayTimer.Fire();
        }
Exemple #26
0
        public IDisposable StartInterval(TimeSpan interval, Action callback)
        {
            NSTimer timer = NSTimer.CreateRepeatingTimer(interval, t =>
            {
                callback();
            });

            NSRunLoop.Main.AddTimer(timer, NSRunLoopMode.Common);
            return(Disposable.Create(() =>
            {
                timer.Invalidate();
                timer.Dispose();
            }));
        }
Exemple #27
0
        private void SaveButton_TouchUpInside(object sender, EventArgs e)
        {
            double recordValue = 0;

            if (this.singleRecordSwitch.On)
            {
                if (Double.TryParse(this.excerciseRecordTextField.Text, out recordValue))
                {
                    ServiceOperator.GetInstance().SaveUserActivityRecord((int)this.userSetsPickerView.SelectedRowInComponent(0), (int)this.userExcercisePickerView.SelectedRowInComponent(0), recordValue);
                    this.PerformSegue("mainToResultsSegue", this);
                }
                else
                {
                    // TODO: Error message to the user
                }
            }
            else if (this.timerSwitch.On)
            {
                this.nsTimer = NSTimer.CreateRepeatingTimer(1, delegate {
                    int minutes = this.timerSeconds / 60;
                    int hours   = minutes / 60;
                    this.timerSeconds++;

                    this.timerInfoLabel.Text = hours + ":" + minutes + ":" + this.timerSeconds % 60;
                });
                if (!this.timerEnabled)
                {
                    this.timerEnabled = true;

                    NSRunLoop.Current.AddTimer(this.nsTimer, NSRunLoopMode.Default);

                    this.userGPSLocationData = new List <GPSLocationData> ();
                    this.Manager.StartLocationUpdates();
                    this.SaveButton.SetTitle("Stop", UIControlState.Normal);
                }
                else
                {
                    this.StoreGPSLocation(this.Manager.GetCurrentLocation());
                    this.Manager.StopLocationUpdates();
                    this.nsTimer.Invalidate();
                    this.nsTimer.Dispose();
                    this.nsTimer = null;
                    ServiceOperator.GetInstance().SaveUserActivityRecord((int)this.userSetsPickerView.SelectedRowInComponent(0), (int)this.userExcercisePickerView.SelectedRowInComponent(0), this.timerSeconds * 1000);
                    this.userGPSLocationData.Clear();
                    //this.timer.Stop ();
                    this.PerformSegue("mainToResultsSegue", this);
                }
            }
        }
Exemple #28
0
        public override object TimerInvoke(Func <bool> action, TimeSpan timeSpan)
        {
            NSTimer timer   = null;
            var     runLoop = NSRunLoop.Current;

            timer = NSTimer.CreateRepeatingTimer(timeSpan, delegate {
                if (!action())
                {
                    timer.Invalidate();
                }
            });
            runLoop.AddTimer(timer, NSRunLoop.NSDefaultRunLoopMode);
            runLoop.AddTimer(timer, NSRunLoop.NSRunLoopModalPanelMode);
            return(timer);
        }
Exemple #29
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            SetElapsedTime();

            var timer = NSTimer.CreateRepeatingTimer(TimeSpan.FromMilliseconds(100), t =>
            {
                if (_stopwatch.IsRunning)
                {
                    SetElapsedTime();
                }
            });

            NSRunLoop.Main.AddTimer(timer, NSRunLoopMode.Common);
        }
Exemple #30
0
        public void AddTimer()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(6, 0))
            {
                Assert.Inconclusive("CMTimebase is new in 6.0");
            }

            using (var tb = new CMTimebase(CMClock.HostTimeClock)) {
                var timer = NSTimer.CreateRepeatingTimer(CMTimebase.VeryLongTimeInterval, delegate { });

                Assert.AreEqual(CMTimebaseError.None, tb.AddTimer(timer, NSRunLoop.Current), "#1");
                Assert.AreEqual(CMTimebaseError.None, tb.SetTimerNextFireTime(timer, new CMTime(100, 2)), "#2");

                tb.RemoveTimer(timer);
            }
        }