Example #1
0
        /// <summary>
        /// Start and stop the sequencer based on the parameter given.
        /// Note that this subscribes to the CurrentlyPlayingChanged in the event handler.
        /// </summary>
        /// <param name="isCurrentlyPlaying">This starts / stops the timer based on a bool</param>
        /// <param name="e">PropertyChangedEventArgs</param>
        private void StartSequencer(object isCurrentlyPlaying, PropertyChangedEventArgs e)
        {
            // Reverse the current playing state flag for the sequencer.
            this.isSequencerRunning = (bool)isCurrentlyPlaying;

            // If the sequencer should play now, then start a new timer thread.
            if (this.isSequencerRunning)
            {
                // Make sure the master timer is not running anymore anywhere.
                if (masterTimer != null)
                {
                    masterTimer.Cancel();
                }

                // Start a new timer at position zero.
                this.currentSequencerPosition = 0;
                masterTimer = ThreadPoolTimer.CreatePeriodicTimer(SequencerMainLoop, this.currentBPMasTimeSpan);
            }
            else
            {
                // Stop the timer.
                if (masterTimer != null)
                {
                    masterTimer.Cancel();
                }
            }
        }
Example #2
0
        private async void CalibrateButton_Click(object sender, RoutedEventArgs e)
        {
            ResetScreensaverTimer();
            SetStatusLabel("CalibrateButton_Click START");
            _startupDelayTimer?.Cancel();

            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                startupStatusLabel.Text = "Calibrating now...";
            });

            _owl.Recalibrate();

            IsTimerEnabled = true;

            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                SetStatusLight(Colors.Green);
                CancelAutoCalibrateButton.Visibility = Visibility.Collapsed;
                startupStatusLabel.Text          = "CALIBRATING COMPLETE";
                mainPivotContainer.SelectedIndex = 1;
            });

            SetStatusLabel("CalibrateButton_Click FINISHED");
        }
Example #3
0
        private void backgroundGrid_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            // Pause the running simulation
            if (simRunning)
            {
                timer.Cancel();
            }

            sim.renderer.SetSimulationTransform(backgroundCanvas.ActualWidth, backgroundCanvas.ActualHeight);
            // var res = DisplayProperties.ResolutionScale;  // don't need this (yet)
            sim.TransformChanged();

            // TBD: restart the running simulation
            if (simRunning)
            {
                timer = ThreadPoolTimer.CreatePeriodicTimer(RunSimTick, new TimeSpan(0, 0, 0, 0, 1000 / (int)ticksPerSecond));
            }

            // TBD: Figure out which event to hook to initialize the initially loaded scenario (or maybe we have to do it this way since we need the initial layout to occur before loading the
            //          starting scenario)
            if (firstRun)
            {
                firstRun = false;
                ScenarioChanging();
                BuiltInScenarios.LoadNineBodiesScenario(sim);
            }
        }
Example #4
0
        public void TaskPause(object sender, RoutedEventArgs e)
        {
            try
            {
                if (IsEachTaskIdEmpty())
                {
                    CommonViewModel.NotifySystemMessage(GetLangMessage.GetMessage("Msg1001"));
                    return;
                }

                Msg = TimeInfoModel.RegisterPause(SelectedEachTaskId);
                if (Msg != null)
                {
                    CommonViewModel.NotifySystemMessage(Msg);
                    return;
                }

                if (NotifyRestTime != null)
                {
                    NotifyRestTime.Cancel();
                }

                CommonViewModel.RecentSelectedEachTaskId = SelectedEachTaskId;

                // Update Recent status
                SetRecentInfo("Msg1011");
            }
            catch
            {
                CommonViewModel.NotifySystemMessage(GetLangMessage.GetMessage("Exception"));
            }
        }
Example #5
0
        private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (_threadPooTimer != null)
            {
                _threadPooTimer.Cancel();
                _threadPooTimer = null;
            }
            TimeSpan period = TimeSpan.FromSeconds(1.0);

            _threadPooTimer = ThreadPoolTimer.CreateTimer(async(source) =>
            {
                if (!_hasBeenResized)
                {
                    await _page.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        if (!_hasBeenResized)
                        {
                            _hasBeenResized = true;
                            ApplicationView.GetForCurrentView().TryResizeView(e.NewSize);
                            _threadPooTimer.Cancel();
                        }
                    });
                }
                else
                {
                    _threadPooTimer.Cancel();
                }
            }, period);
        }
Example #6
0
 public void Cancel()
 {
     if (timer != null)
     {
         timer.Cancel();
     }
 }
Example #7
0
 private void DetailGrid1Play()
 {
     if (isImmersiveMode)
     {
         return;
     }
     if (!detailGridAnimation_FLAG[1])
     {
         if (fengcheTimer != null)
         {
             fengcheTimer.Cancel();
         }
         fengcheTimer = ThreadPoolTimer.CreatePeriodicTimer((work) =>
         {
             if (!Context.EnableDynamic)
             {
                 return;
             }
             var task = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new Windows.UI.Core.DispatchedHandler(() =>
             {
                 fengchezhuan.Angle += FENGCHE_ZHUANSU * Context.Wind.Speed.MPS;
             }));
         }, TimeSpan.FromMilliseconds(16));
         detailGridAnimation_FLAG[1] = true;
     }
 }
 public IAsyncAction StopTraceAsync()
 {
     RtcManager.Instance.EnsureRtcIsInitialized();
     WebRTC.StopTracing();
     _appPerfTimer?.Cancel();
     return(Task.CompletedTask.AsAsyncAction());
 }
Example #9
0
        public void OnWindowSizeChanged(object sender, WindowSizeChangedEventArgs e)
        {
            if (m_timer != null)
            {
                m_timer.Cancel();
                m_timer = null;
            }
            TimeSpan period = TimeSpan.FromSeconds(1.0);

            m_timer = ThreadPoolTimer.CreateTimer(async(source) => {
                if (!resized_already_)
                {
                    await page_.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                        if (!resized_already_)
                        {
                            resized_already_ = true;
                            ApplicationView.GetForCurrentView().TryResizeView(new Windows.Foundation.Size {
                                Width = 500, Height = 840
                            });
                            m_timer.Cancel();
                        }
                    });
                }
                else
                {
                    m_timer.Cancel();
                }
            }, period);
        }
        private void Start_AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            if (_periodicTimer != null)
            {
                _periodicTimer.Cancel();
                _periodicTimer = null;
            }

            // we use temporal copy of beaocnlist for testing purposes
            tmpCollection = new ObservableCollection <Beacon>();
            foreach (Beacon beacon in BeaconCollection)
            {
                // store the listening cycle, so we can show it in the results
                beacon.ListeningCycle = AppSettings.Lifecycle;
                tmpCollection.Add(BeaconFactory.DublicateBeacon(beacon));
            }

            //reset counter
            _listeningCycleCounter = 0;

            //and start the timer
            _periodicTimer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(PeriodicTimerCallback),
                                                                 TimeSpan.FromMilliseconds(AppSettings.Lifecycle));

            //show the test overlay
            ProgressView.Visibility = Visibility.Visible;
        }
        private void PlayMidi(object sender, RoutedEventArgs e)
        {
            bool         IsPlaying = bassManager.Play();
            ToggleButton tb        = sender as ToggleButton;

            if (tb.IsChecked == false)
            {
                PlayButton.IsChecked  = true;
                PauseButton.IsChecked = false;
            }

            PlayButton.IsEnabled = false;
            TimeSpan interval = TimeSpan.FromSeconds(1);

            RefreshCurrentPlaying = ThreadPoolTimer.CreatePeriodicTimer(async(source) =>
            {
                // Update Midi position
                await Dispatcher.RunAsync(CoreDispatcherPriority.High,
                                          () =>
                {
                    // Update UI
                    if (bassManager.IsPlaying())
                    {
                        MainModule.PositionInTime = bassManager.GetMidiPosition();
                        bool CheckEndOfPlaying    = bassManager.IsPlaying();
                        if (!CheckEndOfPlaying)
                        {
                            RefreshCurrentPlaying.Cancel();
                        }
                    }
                });
            }, interval);
        }
Example #12
0
        /// <summary>
        /// On canceled method
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="reason"></param>
        private void OnCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
        {
            cancelRequested = true;
            cancelReason    = reason;

            Timer.Cancel();
            defferal.Complete();
        }
Example #13
0
 public void Dispose()
 {
     if (threadPoolTimer != null)
     {
         threadPoolTimer.Cancel();
         threadPoolTimer = null;
     }
 }
Example #14
0
 void DisableLightAtIndex(int index_)
 {
     if (_spiAvailable)
     {
         _demo.Cancel();
         _lights?.DisableLights(Convert.ToUInt16(1 << (index_ + 1)));
         _demo = ThreadPoolTimer.CreatePeriodicTimer(Shimmer, TimeSpan.FromSeconds(10));
     }
 }
Example #15
0
 /// <summary>
 /// Hide the clipboard clear notification and disables the timer to make it disappear
 /// </summary>
 private void hideClipboardClearNotification()
 {
     if (_notificationTimer != null)
     {
         _notificationTimer.Cancel();
         _notificationTimer = null;
     }
     ClipboardClearNotificationDisplayed = false;
 }
Example #16
0
        public void ResetTimerCycleTimeOut()
        {
            _timerCycleTimeOut2.Cancel();
            _timerCycleTimeOut2 = ThreadPoolTimer.CreatePeriodicTimer(ReciveNoCycles,
                                        TimeSpan.FromSeconds(15));

            _timerCycleTimeOut1.Cancel();
            _timerCycleTimeOut1 = ThreadPoolTimer.CreatePeriodicTimer(MachineNotAlive,
                                        TimeSpan.FromHours(24));
        }
Example #17
0
        /// <summary>
        /// End Countly tracking session.
        /// Call from your App.xaml.cs Application_Deactivated and Application_Closing events.
        /// </summary>
        public static async Task EndSession()
        {
            if (Timer != null)
            {
                Timer.Cancel();
                Timer = null;
            }

            await AddSessionEvent(new EndSession(AppKey, Device.DeviceId), true);
        }
Example #18
0
        // webcameraのスタート
        private async Task StartWebCameraAsync()
        {
            try
            {
                if (_captureManager == null ||
                    _captureManager.CameraStreamState == CameraStreamState.Shutdown ||
                    _captureManager.CameraStreamState == CameraStreamState.NotStreaming)
                {
                    if (_captureManager != null)
                    {
                        // captureManagerのリソースを解放する
                        _captureManager.Dispose();
                    }

                    // LifeCam優先で、それがなければ取得した全カメラIDのリストから先頭のものを使用する
                    MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
                    var allCameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

                    var selectedCamera = allCameras.FirstOrDefault(c => c.Name.Contains("LifeCam")) ?? allCameras.FirstOrDefault();
                    if (selectedCamera != null)
                    {
                        settings.VideoDeviceId = selectedCamera.Id;
                    }

                    _captureManager = new MediaCapture();
                    await _captureManager.InitializeAsync(settings);

                    WebCamCaptureElement.Source = _captureManager;
                }

                if (_captureManager.CameraStreamState == CameraStreamState.NotStreaming)
                {
                    if (_frameProcessingTimer != null)
                    {
                        _frameProcessingTimer.Cancel();
                        _frameProcessingSemaphore.Release();
                    }

                    // 15fpsで動作
                    // 66milsecond毎にCreatePeriodicTimerの第一引き数に渡したHandlerで指定したメソッドが実行される
                    TimeSpan timeInterval = TimeSpan.FromMilliseconds(66);
                    _frameProcessingTimer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(ProcessCurrentVideoFrame), timeInterval);
                    _videoProperties      = _captureManager.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;

                    await _captureManager.StartPreviewAsync();

                    WebCamCaptureElement.Visibility = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
                Debug.Write("6");
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => StatusBlock.Text = $"error: {ex.Message}");
            }
        }
Example #19
0
 public void SetScreensaverEnabled(bool isEnabled)
 {
     IsScreensaverEnabled = isEnabled;
     // If you disable the screensaver in one window, hide any active screensavers in other windows
     IsScreensaverVisible = isEnabled ? IsScreensaverVisible : false;
     _timeoutTimer?.Cancel();
     if (isEnabled)
     {
         _timeoutTimer = ThreadPoolTimer.CreateTimer(TimeoutTimer_Tick, TimeSpan.FromMinutes(1));
     }
 }
Example #20
0
 public void Dispose()
 {
     lock (this)
     {
         if (_nativeTimer != null)
         {
             _nativeTimer.Cancel();
             _nativeTimer = null;
         }
     }
 }
Example #21
0
 private void CreateCancel()
 {
     if (cancelTimer != null)
     {
         cancelTimer.Cancel();
     }
     cancelTimer = ThreadPoolTimer.CreateTimer((x) =>
     {
         clickCount = 0;
     }, TimeSpan.FromSeconds(1));
 }
Example #22
0
        public void TearDownVM()
        {
            _suspended = true;

            Settings.SettingsUpdated -= Settings_SettingsUpdated;

            LogService.Write("Stopping slideshow timer...");

            _slideshowTimer?.Cancel();
            _slideshowTimer = null;
        }
        public void TearDownVM()
        {
            Settings.SettingsUpdated -= Settings_SettingsUpdated;

            LogService.Write("Stopping slideshow timer...");

            _slideshowTimer?.Cancel();
            _slideshowTimer = null;

            _semaphoreSlim.Dispose();
            _semaphoreSlim = null;
        }
Example #24
0
        /// <summary>
        /// Event handler for camera source changes
        /// </summary>
        private async Task StartWebCameraAsync()
        {
            try
            {
                if (_captureManager == null ||
                    _captureManager.CameraStreamState == CameraStreamState.Shutdown ||
                    _captureManager.CameraStreamState == CameraStreamState.NotStreaming)
                {
                    if (_captureManager != null)
                    {
                        _captureManager.Dispose();
                    }

                    // Workaround since my home built-in camera does not work as expected, so have to use my LifeCam
                    MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
                    var allCameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

                    var selectedCamera = allCameras.FirstOrDefault(c => c.Name.Contains("LifeCam")) ?? allCameras.FirstOrDefault();
                    if (selectedCamera != null)
                    {
                        settings.VideoDeviceId = selectedCamera.Id;
                    }
                    //settings.PreviewMediaDescription = new MediaCaptureVideoProfileMediaDescription()

                    _captureManager = new MediaCapture();
                    await _captureManager.InitializeAsync(settings);

                    WebCamCaptureElement.Source = _captureManager;
                }

                if (_captureManager.CameraStreamState == CameraStreamState.NotStreaming)
                {
                    if (_frameProcessingTimer != null)
                    {
                        _frameProcessingTimer.Cancel();
                        _frameProcessingSemaphore.Release();
                    }

                    TimeSpan timerInterval = TimeSpan.FromMilliseconds(66); //15fps
                    _frameProcessingTimer = ThreadPoolTimer.CreatePeriodicTimer(new TimerElapsedHandler(ProcessCurrentVideoFrame), timerInterval);

                    _videoProperties = _captureManager.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;

                    await _captureManager.StartPreviewAsync();

                    WebCamCaptureElement.Visibility = Visibility.Visible;
                }
            }
            catch (Exception ex)
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => StatusBlock.Text = $"error: {ex.Message}");
            }
        }
Example #25
0
        public IAsyncAction DisposeAsync()
        {
            return(Task.Run(async() =>
            {
                if (tempTimer != null)
                {
                    tempTimer.Cancel();
                    tempTimer = null;
                }

                await this.DisposeInternal();
            }).AsAsyncAction());
        }
Example #26
0
        private void ReadingChanged(object sender, AccelerometerReadingChangedEventArgs e)
        {
            TestCount++;

            AccelerometerReading reading = e.Reading;

            string sMessage = "";

            /*
             * if (reading.AccelerationX > 0 && reading.AccelerationX < 0.1 && reading.AccelerationY > -0.02 && reading.AccelerationY < 0.05 && reading.AccelerationZ > -1.01 && reading.AccelerationZ < -0.93)
             * {
             *  sMessage = "";
             *  sMessage += "Round" + TestRound + "->" + TestCount + ":";
             *  sMessage += string.Format(" Accelerometer X({0,5:0.00})", reading.AccelerationX);
             *  sMessage += string.Format(" Y({0,5:0.00})", reading.AccelerationY);
             *  sMessage += string.Format(" Z({0,5:0.00})", reading.AccelerationZ);
             *  sMessage += "\r\n";
             *
             *  Alog.WriteText(sMessage);
             *
             * }
             * else
             * {
             *  sMessage = "";
             *  sMessage += "Round" + TestRound + "->" + TestCount + ":";
             *  sMessage += "Accelerometer Failed.";
             *  sMessage += "\r\n";
             *
             *  Alog.WriteText(sMessage);
             * }
             */

            sMessage += "Round" + TestRound + "->" + TestCount + ":";
            sMessage += string.Format(" Accelerometer X({0,5:0.00})", reading.AccelerationX);
            sMessage += string.Format(" Y({0,5:0.00})", reading.AccelerationY);
            sMessage += string.Format(" Z({0,5:0.00})", reading.AccelerationZ);
            sMessage += "\r\n";

            Alog.WriteText(sMessage);


            _accelerometer.ReportInterval  = 0;
            _accelerometer.ReadingChanged -= new Windows.Foundation.TypedEventHandler <Windows.Devices.Sensors.Accelerometer, AccelerometerReadingChangedEventArgs>(ReadingChanged);

            if (TestCount >= TestMaxCount)
            {
                Atimer.Cancel();
                TestCount = 0;
                Ftimer    = ThreadPoolTimer.CreatePeriodicTimer(Flash_Timer_Tick, TimeSpan.FromMilliseconds(5000));
            }
        }
 private void Rectangle_PointerEntered(object sender, PointerRoutedEventArgs e)
 {
     if (PeriodicTimer != null)
     {
         PeriodicTimer.Cancel();
     }
     nv1.Content   = "Dashboard";
     nv2.Content   = "Account";
     nv3.Content   = "Journal";
     nv4.Content   = "Ledger";
     nv1.Padding   = new Thickness(0, 0, 16, 0);
     vwttle.Width  = 64;
     vwttle.Height = 64;
 }
        private void Login(string username, string password)
        {
            JObject data = new JObject();

            try
            {
                data.Add("login", username);
                data.Add("password", password);
                data.Add("sent", HUtil.DateTime2Timestamps(DateTime.UtcNow));
                if (options.Context != null)
                {
                    data.Add("context", options.Context);
                }

                socketIO.Emit("hConnect", data);
            }
            catch (Exception e)
            {
                if (socketIO != null)
                {
                    Disconnect();
                }
                if (connTimeoutTimer != null)
                {
                    connTimeoutTimer.Cancel();
                    connTimeoutTimer = null;
                }
                updateStatus(ConnectionStatus.DISCONNECTED, ConnectionErrors.TECH_ERROR, e.Message);
            }
        }
Example #29
0
        private void MoveTimer_Tick(ThreadPoolTimer timer)
        {
            _moveTimer?.Cancel();
            if (!IsScreensaverEnabled)
            {
                return;
            }

            IsImageVisible    = false;
            LeftImagePosition = _randomizer.NextDouble() * (PageWidth - ImageWidth);
            TopImagePosition  = _randomizer.NextDouble() * (PageHeight - ImageHeight);
            IsImageVisible    = true;

            _moveTimer = ThreadPoolTimer.CreateTimer(MoveTimer_Tick, TimeSpan.FromSeconds(5));
        }
 private void StopTimer( )
 {
     if (t1 != null)
     {
         t1.Cancel( );
     }
 }